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