When I'm fetching the messages from fire base new messages are appears randomly in the list view how I can set the new messages on the bottom of my list view in flutter?
Here is the code:
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
StreamBuilder<QuerySnapshot>(
stream: _firestore.collection('messages').snapshots(),
builder: (context, snapshot) {
List<MyMessageContainer> messageWidget = [];
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(
backgroundColor: Colors.lightBlue,
),
);
}
final messagesDoc = snapshot.data.docs.reversed;
for (var messageData in messagesDoc) {
final messageBody = messageData.data();
final messageText = messageBody['text'];
final messageSender = messageBody['sender'];
final msg = MyMessageContainer(
message: messageText,
sender: messageSender,
isCurrentUser: messageSender == user.email ? true : false,
);
messageWidget.add(msg);
}
return Expanded(
child: ListView(
reverse: true,
children: messageWidget,
),
);
},
),
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…