feat: Dynamic appbar elevation and FAB in chat list

This commit is contained in:
Christian Pauly 2021-05-30 12:41:10 +02:00
parent 34b8751328
commit 3d7e1554bf
2 changed files with 28 additions and 10 deletions

View File

@ -32,6 +32,7 @@ class ChatList extends StatefulWidget {
}
class ChatListController extends State<ChatList> {
final ScrollController scrollController = ScrollController();
StreamSubscription _intentDataStreamSubscription;
StreamSubscription _intentFileStreamSubscription;
@ -42,6 +43,15 @@ class ChatListController extends State<ChatList> {
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<SharedMediaFile> files) {
if (files?.isEmpty ?? true) return;
VRouter.of(context).push('/rooms');
@ -109,6 +119,7 @@ class ChatListController extends State<ChatList> {
@override
void initState() {
_initReceiveSharingIntent();
scrollController.addListener(updateScrolledTop);
super.initState();
}
@ -117,6 +128,7 @@ class ChatListController extends State<ChatList> {
_intentDataStreamSubscription?.cancel();
_intentFileStreamSubscription?.cancel();
_intentUriStreamSubscription?.cancel();
scrollController.removeListener(updateScrolledTop);
super.dispose();
}

View File

@ -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,
));
});