'how to streambuilder auto scroll in send new message
I'm creating an app that has a group chat section and I'm facing a problem I need when I send a new message it automatically scrolls to the last message I sent like chat apps ? This is my code
StreamBuilder<QuerySnapshot>(
stream: _firestore.collection('messages').orderBy('time').snapshots(),
builder: (context, snapshot){
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: Container(
height: 40,
width: 40,
child: CircularProgressIndicator(),
),
);
}
List<messageLine> messageWidgets = [];
final messages = snapshot.data!.docs;
for(var message in messages){
final messageText = message.data().toString().contains('text') ? message.get('text') : '';
final messagesender = message.data().toString().contains('sender') ? message.get('sender') : '';
final currentUser = Signinuser.email;
if (currentUser == messagesender){
}
final messageWidget = messageLine(sender: messagesender,text: messageText,isme: currentUser == messagesender,);
messageWidgets.add(messageWidget);
}
return Expanded(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/chatBack.png'),
fit: BoxFit.cover
)
),
child: ListView(
padding: EdgeInsets.symmetric(
horizontal: 10,vertical: 20
),
children: messageWidgets
),
),
);
},),
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
