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.
pull/324/head
Strycher 3 days ago
parent 82c1e73b51
commit e194800541

@ -314,10 +314,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
/// panel stays docked and only the chat area changes. The back stack is /// panel stays docked and only the chat area changes. The back stack is
/// untouched, so system back still returns to the channel list. /// untouched, so system back still returns to the channel list.
void _switchChannel(Channel channel) { void _switchChannel(Channel channel) {
final scaffold = Scaffold.maybeOf(context); // The drawer closes itself in ChannelDrawerList, which has a context
if (scaffold?.isDrawerOpen ?? false) { // inside it.
Navigator.pop(context);
}
if (channel.index == _currentChannel.index) return; if (channel.index == _currentChannel.index) return;
final connector = context.read<MeshCoreConnector>(); final connector = context.read<MeshCoreConnector>();

@ -638,12 +638,8 @@ class _ChannelsScreenState extends State<ChannelsScreen>
final connector = context.read<MeshCoreConnector>(); final connector = context.read<MeshCoreConnector>();
final unread = connector.getUnreadCountForChannelIndex(channel.index); final unread = connector.getUnreadCountForChannelIndex(channel.index);
connector.markChannelRead(channel.index); connector.markChannelRead(channel.index);
// Close the drawer if the tap came from it, so it is not left open behind // The drawer closes itself in ChannelDrawerList, which has a context
// the chat screen when the user comes back. // inside it.
final scaffold = Scaffold.maybeOf(context);
if (scaffold?.isDrawerOpen ?? false) {
Navigator.pop(context);
}
await Future.delayed(const Duration(milliseconds: 50)); await Future.delayed(const Duration(milliseconds: 50));
if (!context.mounted) return; if (!context.mounted) return;
Navigator.push( Navigator.push(

@ -91,7 +91,16 @@ class _ChannelDrawerTile extends StatelessWidget {
), ),
), ),
trailing: unread > 0 ? UnreadBadge(count: unread) : null, 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();
},
); );
} }
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.