I’m getting a stream of words from server. The objective is to combine the words into a single sentence dynamically. Now what happens is as follows, the values are appended, but the entire string is duplicated whenever a new letter is added.
eg: hi , how are you ? // stream of words or letters
Expected : hi, how are you?
what im getting is as follows
hi
hi,
hi, how
hi, how are
hi, how are you
hi, how are you ?
My objective is dynamically add this to a string so i can pass that to the ui to render
StringBuffer buffer = StringBuffer();
String newPart = '';
subscription = _channel.stream.listen(
(message) {
final actualMessage = message['message']; // from where i get data or values
if (actualMessage != 'END') {
newPart += actualMessage;
buffer.clear();
buffer.write(newPart);
debugPrint(buffer.toString().trim());
add(UiEvent.response(
message: buffer.toString().trim()));
// lastMessage = '';
}
},
onError: (error) {
debugPrint("stream Error $error");
},
);
i need to dynamically append data and send it to ui. what am i missing? how can i implement this correctly?