Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others


0 votes
in Technique[技术] by (71.8m points)

android - How to get new messages on bottom of the list view

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>[
              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,
                return Expanded(
                  child: ListView(
                    reverse: true,
                    children: messageWidget,

Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Firestore has no built-in way to identify "new" messages. If you want that, you'll have to store a value in each document with a timestamp.

When you've done that, you can get them in the correct order in your code with:


Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share