diff --git a/lib/pages/chat_list.dart b/lib/pages/chat_list.dart index 32d947d0..007dfab8 100644 --- a/lib/pages/chat_list.dart +++ b/lib/pages/chat_list.dart @@ -32,6 +32,7 @@ class ChatList extends StatefulWidget { } class ChatListController extends State { + final ScrollController scrollController = ScrollController(); StreamSubscription _intentDataStreamSubscription; StreamSubscription _intentFileStreamSubscription; @@ -42,6 +43,15 @@ class ChatListController extends State { String get activeChat => VRouter.of(context).pathParameters['roomid']; + bool scrolledTop = true; + + void updateScrolledTop() { + final newScrolledTop = scrollController.offset == 0; + if (scrolledTop != newScrolledTop) { + setState(() => scrolledTop = newScrolledTop); + } + } + void _processIncomingSharedFiles(List files) { if (files?.isEmpty ?? true) return; VRouter.of(context).push('/rooms'); @@ -109,6 +119,7 @@ class ChatListController extends State { @override void initState() { _initReceiveSharingIntent(); + scrollController.addListener(updateScrolledTop); super.initState(); } @@ -117,6 +128,7 @@ class ChatListController extends State { _intentDataStreamSubscription?.cancel(); _intentFileStreamSubscription?.cancel(); _intentUriStreamSubscription?.cancel(); + scrollController.removeListener(updateScrolledTop); super.dispose(); } diff --git a/lib/pages/views/chat_list_view.dart b/lib/pages/views/chat_list_view.dart index 57de43a9..7e28f888 100644 --- a/lib/pages/views/chat_list_view.dart +++ b/lib/pages/views/chat_list_view.dart @@ -1,5 +1,4 @@ import 'package:famedlysdk/famedlysdk.dart'; -import 'package:fluffychat/config/themes.dart'; import 'package:fluffychat/pages/chat_list.dart'; import 'package:fluffychat/widgets/connection_status_header.dart'; import 'package:fluffychat/widgets/list_items/chat_list_item.dart'; @@ -35,10 +34,7 @@ class ChatListView extends StatelessWidget { }, child: Scaffold( appBar: AppBar( - elevation: MediaQuery.of(context).size.width > - FluffyThemes.columnWidth * 2 - ? 1 - : null, + elevation: controller.scrolledTop ? 0 : null, leading: selectMode == SelectMode.normal ? null : IconButton( @@ -207,6 +203,7 @@ class ChatListView extends StatelessWidget { final totalCount = rooms.length; return ListView.builder( itemCount: totalCount, + controller: controller.scrollController, itemBuilder: (BuildContext context, int i) => ChatListItem( rooms[i], @@ -233,11 +230,20 @@ class ChatListView extends StatelessWidget { ), ]), floatingActionButton: selectMode == SelectMode.normal - ? FloatingActionButton( - onPressed: () => - VRouter.of(context).push('/newprivatechat'), - child: Icon(CupertinoIcons.chat_bubble), - ) + ? controller.scrolledTop + ? FloatingActionButton.extended( + heroTag: 'main_fab', + onPressed: () => + VRouter.of(context).push('/newprivatechat'), + icon: Icon(CupertinoIcons.chat_bubble), + label: Text(L10n.of(context).newChat), + ) + : FloatingActionButton( + heroTag: 'main_fab', + onPressed: () => + VRouter.of(context).push('/newprivatechat'), + child: Icon(CupertinoIcons.chat_bubble), + ) : null, )); });