aboutsummaryrefslogtreecommitdiff
path: root/lib/screens
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2023-05-22 09:30:03 -0600
committerIván Ávalos <avalos@disroot.org>2023-05-22 09:30:03 -0600
commitb43b43411cf2a06bbb4af0761d8acf2807718945 (patch)
tree0636fd111273a9e6204195a9b48c9fb1f5e5f42f /lib/screens
parent36306e093d1bd3ade5dbc2a93e75bbfc94cbb058 (diff)
downloadlinkchat-b43b43411cf2a06bbb4af0761d8acf2807718945.tar.gz
linkchat-b43b43411cf2a06bbb4af0761d8acf2807718945.tar.bz2
linkchat-b43b43411cf2a06bbb4af0761d8acf2807718945.zip
Auto scroll to bottom
Diffstat (limited to 'lib/screens')
-rw-r--r--lib/screens/chat_screen.dart11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/screens/chat_screen.dart b/lib/screens/chat_screen.dart
index d3d71ad..bd0d5d7 100644
--- a/lib/screens/chat_screen.dart
+++ b/lib/screens/chat_screen.dart
@@ -22,6 +22,8 @@ class _ChatScreenState extends State<ChatScreen> {
final Auth _auth = Auth();
final Database _db = Database();
+ final ScrollController _scroll = ScrollController();
+
@override
Widget build(BuildContext context) {
List<dynamic> arguments =
@@ -64,8 +66,17 @@ class _ChatScreenState extends State<ChatScreen> {
stream: _db.getMessagesByGroupId(group!.id!),
builder: (context, snapshot) {
if (snapshot.hasData) {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ if (_scroll.hasClients) {
+ _scroll.animateTo(_scroll.position.maxScrollExtent,
+ duration: const Duration(milliseconds: 500),
+ curve: Curves.fastOutSlowIn);
+ }
+ });
+
List<Message> msgs = snapshot.data!;
return ListView.builder(
+ controller: _scroll,
padding: const EdgeInsets.only(bottom: 80.0),
itemCount: snapshot.data!.length,
itemBuilder: (context, index) => ChatBubble(