Comments (3)
As a workaround, if you get a stream, you can use something like this when you receive the stream.
void _updateFirstMessageText(String newText, {bool replace = false}) {
assert(
_messages.first is types.TextMessage,
'First message must be a text message',
);
final firstMessage = _messages.first as types.TextMessage;
final updatedText = replace ? newText : firstMessage.text + newText;
final updatedMessage = firstMessage.copyWith(
text: updatedText,
) as types.TextMessage;
setState(() {
_messages.removeAt(0);
_addMessage(updatedMessage);
});
}
You can also emulate streamed text with something like this
bool _isStreaming = false;
final List<String> _messageQueue = [];
void _onTextReceived(String newText) {
_messageQueue.add(newText);
if (!_isStreaming) {
setState(() {
final updatedMessage = _messages.first.copyWith(
text: _messages.first.text + newText,
) as types.TextMessage;
_messages.removeAt(0);
_addMessage(updatedMessage);
});
}
}
Future<void> _startStreamingMessages() async {
_isStreaming = true;
while (_messageQueue.isNotEmpty) {
final nextMessage = _messageQueue.removeAt(0);
await _streamText(nextMessage);
}
_isStreaming = false;
}
Future<void> _streamText(String message) async {
var currentIndex = 0;
final completer = Completer<void>();
Timer.periodic(const Duration(milliseconds: 15), (timer) { // adjust this for the "speed" of the stream
if (currentIndex < message.length) {
setState(() {
final updatedMessage = _messages.first.copyWith(
text: _messages.first.text + message[currentIndex],
) as types.TextMessage;
_messages.removeAt(0);
_addMessage(updatedMessage);
currentIndex++;
});
} else {
timer.cancel();
completer.complete();
}
});
from flutter_chat_ui.
no possible with v1
. Will try to do in v2
. (but please do not wait for me cause it might take lots of time - find an alternative if possible)
from flutter_chat_ui.
When do you plan to release v2 ?
from flutter_chat_ui.
Related Issues (20)
- Transparent `customBottomWidget` HOT 3
- PopScope and TextScaler aren't found HOT 1
- How to copy and paste the image to inputbox and send images? HOT 1
- Unresolved Chat class
- Janky scroll on chat list HOT 3
- Update on V2 release and checklist HOT 3
- message.copyWith(status: types.Status.status) does not working
- Using ChatList Component as a Standalone Widget HOT 1
- messageList.insert(0, message) always shows incoming messages as my own. HOT 3
- flutter build web --wasm failed due to RangeError HOT 8
- Alternative input options (instead of text input) for a chat game HOT 2
- How do I make message that links to another page HOT 1
- The argument type 'ScrollController' can't be assigned to the parameter type 'AutoScrollController?'.
- the send button doesnt appear on my phone till i press symbols or space also in my emulator but it works perfectly with the pc keyboard on the emulator HOT 8
- Chat image HTTP request failed. Change its text HOT 1
- Need to add CupertinoContextMenu to the chat bubble for the function of copying chat content. HOT 1
- How to include edit message feature? HOT 1
- Removing margin from the input field HOT 6
- Add support of a context to all `*Builder`s HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_chat_ui.