fix: show success snackbar from HomeScreen instead of dying dialog
The AddCarDialog now pops with a boolean result instead of trying to show a SnackBar on its own context after Navigator.pop() disposes it. HomeScreen shows the snackbar using its own stable mounted context.
This commit is contained in:
parent
16d1145efd
commit
c104ec16ed
1 changed files with 19 additions and 10 deletions
|
|
@ -411,12 +411,23 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||
if (!mounted) return;
|
||||
setState(() => _isBusy = false);
|
||||
|
||||
if (data != null) {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => data != null
|
||||
? _AlreadyExistsDialog(hwId: hwId)
|
||||
: _AddCarDialog(hwId: hwId),
|
||||
builder: (_) => _AlreadyExistsDialog(hwId: hwId),
|
||||
);
|
||||
} else {
|
||||
// Dialog returns true if the car was added successfully.
|
||||
final added = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (_) => _AddCarDialog(hwId: hwId),
|
||||
);
|
||||
if (added == true && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('$hwId added to your collection! 🎉')),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() => _isBusy = false);
|
||||
|
|
@ -469,10 +480,8 @@ class _AddCarDialogState extends State<_AddCarDialog> {
|
|||
'user_id': supabase.auth.currentUser!.id,
|
||||
});
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('${widget.hwId} added to your collection! 🎉')),
|
||||
);
|
||||
// Return true to signal success — snackbar shown by HomeScreen.
|
||||
Navigator.of(context).pop(true);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() => _isAdding = false);
|
||||
|
|
|
|||
Loading…
Reference in a new issue