fix(channels): make edit/delete actions use parent context after bottom sheet closes

Root cause: edit/delete dialogs were opened from the sheet context after Navigator.pop, so context.mounted was false and follow-up actions never ran.

Also keeps async await/error handling for channel edit/delete so failures surface to users instead of silently dropping.
This commit is contained in:
just_stuff_tm
2026-02-20 01:28:13 -05:00
parent 0c4910e149
commit ba2763a3f6
+46 -24
View File
@@ -478,9 +478,10 @@ class _ChannelsScreenState extends State<ChannelsScreen>
MeshCoreConnector connector, MeshCoreConnector connector,
Channel channel, Channel channel,
) { ) {
final parentContext = context;
showModalBottomSheet( showModalBottomSheet(
context: context, context: parentContext,
builder: (context) => SafeArea( builder: (sheetContext) => SafeArea(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
@@ -488,10 +489,10 @@ class _ChannelsScreenState extends State<ChannelsScreen>
leading: const Icon(Icons.edit_outlined), leading: const Icon(Icons.edit_outlined),
title: Text(context.l10n.channels_editChannel), title: Text(context.l10n.channels_editChannel),
onTap: () async { onTap: () async {
Navigator.pop(context); Navigator.pop(sheetContext);
await Future.delayed(const Duration(milliseconds: 100)); await Future.delayed(const Duration(milliseconds: 100));
if (context.mounted) { if (parentContext.mounted) {
_showEditChannelDialog(context, connector, channel); _showEditChannelDialog(parentContext, connector, channel);
} }
}, },
), ),
@@ -502,10 +503,10 @@ class _ChannelsScreenState extends State<ChannelsScreen>
style: const TextStyle(color: Colors.red), style: const TextStyle(color: Colors.red),
), ),
onTap: () async { onTap: () async {
Navigator.pop(context); Navigator.pop(sheetContext);
await Future.delayed(const Duration(milliseconds: 100)); await Future.delayed(const Duration(milliseconds: 100));
if (context.mounted) { if (parentContext.mounted) {
_confirmDeleteChannel(context, connector, channel); _confirmDeleteChannel(parentContext, connector, channel);
} }
}, },
), ),
@@ -1415,7 +1416,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
child: Text(dialogContext.l10n.common_cancel), child: Text(dialogContext.l10n.common_cancel),
), ),
FilledButton( FilledButton(
onPressed: () { onPressed: () async {
final name = nameController.text.trim(); final name = nameController.text.trim();
final pskHex = pskController.text.trim(); final pskHex = pskController.text.trim();
@@ -1432,13 +1433,25 @@ class _ChannelsScreenState extends State<ChannelsScreen>
} }
Navigator.pop(dialogContext); Navigator.pop(dialogContext);
connector.setChannel(channel.index, name, psk); try {
connector.setChannelSmazEnabled(channel.index, smazEnabled); await connector.setChannel(channel.index, name, psk);
ScaffoldMessenger.of(context).showSnackBar( await connector.setChannelSmazEnabled(
SnackBar( channel.index,
content: Text(context.l10n.channels_channelUpdated(name)), smazEnabled,
), );
); if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(context.l10n.channels_channelUpdated(name)),
),
);
} catch (e, st) {
debugPrint(st.toString());
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to update channel: $e')),
);
}
}, },
child: Text(dialogContext.l10n.common_save), child: Text(dialogContext.l10n.common_save),
), ),
@@ -1466,16 +1479,25 @@ class _ChannelsScreenState extends State<ChannelsScreen>
child: Text(dialogContext.l10n.common_cancel), child: Text(dialogContext.l10n.common_cancel),
), ),
TextButton( TextButton(
onPressed: () { onPressed: () async {
Navigator.pop(dialogContext); Navigator.pop(dialogContext);
connector.deleteChannel(channel.index); try {
ScaffoldMessenger.of(context).showSnackBar( await connector.deleteChannel(channel.index);
SnackBar( if (!context.mounted) return;
content: Text( ScaffoldMessenger.of(context).showSnackBar(
context.l10n.channels_channelDeleted(channel.name), SnackBar(
content: Text(
context.l10n.channels_channelDeleted(channel.name),
),
), ),
), );
); } catch (e, st) {
debugPrint(st.toString());
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to delete channel: $e')),
);
}
}, },
child: Text( child: Text(
dialogContext.l10n.common_delete, dialogContext.l10n.common_delete,