I'm trying to make my listview always focus on the last element in a chat, but I don't know how to do it, I appreciate if someone can help me
Widget ChatMessageList(){
    return StreamBuilder(
      stream: chatMessageStream,
      builder: (context, snapshot){
        return snapshot.hasData ? ListView.builder(
          controller: _scrollController,
          itemCount: snapshot.data.documents.length,
          itemBuilder: (context, index){
            return MessageTile(snapshot.data.documents[index].data()['message'],
                snapshot.data.documents[index].data()['sendBy'] == userSnapshop.uid);
          }
        ) : Container();
      },
    );
  }
                List view can be reverse by wrapping another scrollable widget.
so you just need to wrap your ListView by SingleChildScrollView and change the reading direction by revers property.
SingleChildScrollView(
        reverse: true,
        child: ListView.builder(
          shrinkWrap: true,
          physics: NeverScrollableScrollPhysics(),
          itemCount: 100,
          itemBuilder: (context, index) => Text(
            index.toString(),
          ),
        ),
      )
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With