From e194800541dec4e92598734923d91beee041ca81 Mon Sep 17 00:00:00 2001 From: Strycher Date: Sat, 18 Jul 2026 22:52:09 -0400 Subject: [PATCH] fix(#289): close the unpinned drawer when a channel is picked Picking a channel from an unpinned drawer switched the channel but left the drawer hanging open over it. The close was attempted from the screen's State context, which sits above the Scaffold that AppShell builds, so Scaffold.maybeOf never resolved it and isDrawerOpen was always false. The close now happens in the drawer tile, whose context is inside the Drawer, and uses closeDrawer() rather than popping a route. Pinned layouts have no drawer to close and are unaffected. Removes the two dead close attempts in ChannelChatScreen and ChannelsScreen. flutter analyze clean, dart format applied. Not yet run on hardware. --- lib/screens/channel_chat_screen.dart | 6 ++---- lib/screens/channels_screen.dart | 8 ++------ lib/widgets/channel_drawer_list.dart | 11 ++++++++++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/screens/channel_chat_screen.dart b/lib/screens/channel_chat_screen.dart index de93025..fb9ff0d 100644 --- a/lib/screens/channel_chat_screen.dart +++ b/lib/screens/channel_chat_screen.dart @@ -314,10 +314,8 @@ class _ChannelChatScreenState extends State { /// panel stays docked and only the chat area changes. The back stack is /// untouched, so system back still returns to the channel list. void _switchChannel(Channel channel) { - final scaffold = Scaffold.maybeOf(context); - if (scaffold?.isDrawerOpen ?? false) { - Navigator.pop(context); - } + // The drawer closes itself in ChannelDrawerList, which has a context + // inside it. if (channel.index == _currentChannel.index) return; final connector = context.read(); diff --git a/lib/screens/channels_screen.dart b/lib/screens/channels_screen.dart index d6e3116..f7deb8b 100644 --- a/lib/screens/channels_screen.dart +++ b/lib/screens/channels_screen.dart @@ -638,12 +638,8 @@ class _ChannelsScreenState extends State final connector = context.read(); final unread = connector.getUnreadCountForChannelIndex(channel.index); connector.markChannelRead(channel.index); - // Close the drawer if the tap came from it, so it is not left open behind - // the chat screen when the user comes back. - final scaffold = Scaffold.maybeOf(context); - if (scaffold?.isDrawerOpen ?? false) { - Navigator.pop(context); - } + // The drawer closes itself in ChannelDrawerList, which has a context + // inside it. await Future.delayed(const Duration(milliseconds: 50)); if (!context.mounted) return; Navigator.push( diff --git a/lib/widgets/channel_drawer_list.dart b/lib/widgets/channel_drawer_list.dart index 3846621..1527a28 100644 --- a/lib/widgets/channel_drawer_list.dart +++ b/lib/widgets/channel_drawer_list.dart @@ -91,7 +91,16 @@ class _ChannelDrawerTile extends StatelessWidget { ), ), trailing: unread > 0 ? UnreadBadge(count: unread) : null, - onTap: onTap, + onTap: () { + // Close from here, not from the caller: this context is inside the + // Drawer, whereas a screen's State context sits above the Scaffold and + // would never resolve it. Pinned layouts have no drawer to close. + final scaffold = Scaffold.maybeOf(context); + if (scaffold?.isDrawerOpen ?? false) { + scaffold!.closeDrawer(); + } + onTap(); + }, ); } }