From 623b6f0c76e5968e662e6474b0cdfd98ccb0b131 Mon Sep 17 00:00:00 2001 From: Deven Joshi Date: Mon, 18 Jan 2021 20:04:48 +0530 Subject: [PATCH] fix: Fixed focus issue --- packages/flutter_widgets/example/lib/main.dart | 4 ++++ .../flutter_widgets/lib/src/channel_list_header.dart | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/flutter_widgets/example/lib/main.dart b/packages/flutter_widgets/example/lib/main.dart index 460a80a3..86cfa52d 100644 --- a/packages/flutter_widgets/example/lib/main.dart +++ b/packages/flutter_widgets/example/lib/main.dart @@ -156,6 +156,9 @@ class _HomePageState extends State { onNewChatButtonTap: () { Navigator.pushNamed(context, Routes.NEW_CHAT); }, + preNavigationCallback: () { + FocusScope.of(context).requestFocus(FocusNode()); + }, ), drawer: _buildDrawer(context, user), drawerEdgeDragWidth: 50, @@ -519,6 +522,7 @@ class _ChannelListPageState extends State { ); }, onItemTap: (messageResponse) async { + FocusScope.of(context).requestFocus(FocusNode()); final client = StreamChat.of(context).client; final message = messageResponse.message; final channel = client.channel( diff --git a/packages/flutter_widgets/lib/src/channel_list_header.dart b/packages/flutter_widgets/lib/src/channel_list_header.dart index b6bf3ca7..e8583d11 100644 --- a/packages/flutter_widgets/lib/src/channel_list_header.dart +++ b/packages/flutter_widgets/lib/src/channel_list_header.dart @@ -55,6 +55,7 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget { this.onUserAvatarTap, this.onNewChatButtonTap, this.showConnectionStateTile = false, + this.preNavigationCallback, }) : super(key: key); /// Pass this if you don't have a [Client] in your widget tree. @@ -72,6 +73,8 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget { final bool showConnectionStateTile; + final VoidCallback preNavigationCallback; + @override Widget build(BuildContext context) { final _client = client ?? StreamChat.of(context).client; @@ -110,8 +113,13 @@ class ChannelListHeader extends StatelessWidget implements PreferredSizeWidget { child: UserAvatar( user: user, showOnlineStatus: false, - onTap: - onUserAvatarTap ?? (_) => Scaffold.of(context).openDrawer(), + onTap: onUserAvatarTap ?? + (_) { + if (preNavigationCallback != null) { + preNavigationCallback(); + } + Scaffold.of(context).openDrawer(); + }, borderRadius: BorderRadius.circular(20), constraints: BoxConstraints.tightFor( height: 40,