mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-19 16:44:11 +01:00
feat: Dynamic appbar elevation and FAB in chat list
This commit is contained in:
parent
34b8751328
commit
3d7e1554bf
@ -32,6 +32,7 @@ class ChatList extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ChatListController extends State<ChatList> {
|
class ChatListController extends State<ChatList> {
|
||||||
|
final ScrollController scrollController = ScrollController();
|
||||||
StreamSubscription _intentDataStreamSubscription;
|
StreamSubscription _intentDataStreamSubscription;
|
||||||
|
|
||||||
StreamSubscription _intentFileStreamSubscription;
|
StreamSubscription _intentFileStreamSubscription;
|
||||||
@ -42,6 +43,15 @@ class ChatListController extends State<ChatList> {
|
|||||||
|
|
||||||
String get activeChat => VRouter.of(context).pathParameters['roomid'];
|
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) {
|
void _processIncomingSharedFiles(List<SharedMediaFile> files) {
|
||||||
if (files?.isEmpty ?? true) return;
|
if (files?.isEmpty ?? true) return;
|
||||||
VRouter.of(context).push('/rooms');
|
VRouter.of(context).push('/rooms');
|
||||||
@ -109,6 +119,7 @@ class ChatListController extends State<ChatList> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
_initReceiveSharingIntent();
|
_initReceiveSharingIntent();
|
||||||
|
scrollController.addListener(updateScrolledTop);
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +128,7 @@ class ChatListController extends State<ChatList> {
|
|||||||
_intentDataStreamSubscription?.cancel();
|
_intentDataStreamSubscription?.cancel();
|
||||||
_intentFileStreamSubscription?.cancel();
|
_intentFileStreamSubscription?.cancel();
|
||||||
_intentUriStreamSubscription?.cancel();
|
_intentUriStreamSubscription?.cancel();
|
||||||
|
scrollController.removeListener(updateScrolledTop);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
import 'package:fluffychat/config/themes.dart';
|
|
||||||
import 'package:fluffychat/pages/chat_list.dart';
|
import 'package:fluffychat/pages/chat_list.dart';
|
||||||
import 'package:fluffychat/widgets/connection_status_header.dart';
|
import 'package:fluffychat/widgets/connection_status_header.dart';
|
||||||
import 'package:fluffychat/widgets/list_items/chat_list_item.dart';
|
import 'package:fluffychat/widgets/list_items/chat_list_item.dart';
|
||||||
@ -35,10 +34,7 @@ class ChatListView extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
elevation: MediaQuery.of(context).size.width >
|
elevation: controller.scrolledTop ? 0 : null,
|
||||||
FluffyThemes.columnWidth * 2
|
|
||||||
? 1
|
|
||||||
: null,
|
|
||||||
leading: selectMode == SelectMode.normal
|
leading: selectMode == SelectMode.normal
|
||||||
? null
|
? null
|
||||||
: IconButton(
|
: IconButton(
|
||||||
@ -207,6 +203,7 @@ class ChatListView extends StatelessWidget {
|
|||||||
final totalCount = rooms.length;
|
final totalCount = rooms.length;
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: totalCount,
|
itemCount: totalCount,
|
||||||
|
controller: controller.scrollController,
|
||||||
itemBuilder: (BuildContext context, int i) =>
|
itemBuilder: (BuildContext context, int i) =>
|
||||||
ChatListItem(
|
ChatListItem(
|
||||||
rooms[i],
|
rooms[i],
|
||||||
@ -233,11 +230,20 @@ class ChatListView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
floatingActionButton: selectMode == SelectMode.normal
|
floatingActionButton: selectMode == SelectMode.normal
|
||||||
? FloatingActionButton(
|
? controller.scrolledTop
|
||||||
onPressed: () =>
|
? FloatingActionButton.extended(
|
||||||
VRouter.of(context).push('/newprivatechat'),
|
heroTag: 'main_fab',
|
||||||
child: Icon(CupertinoIcons.chat_bubble),
|
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,
|
: null,
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user