diff --git a/lib/main.dart b/lib/main.dart index 2a28b2e..5b676aa 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -411,12 +411,23 @@ class _HomeScreenState extends State { if (!mounted) return; setState(() => _isBusy = false); - await showDialog( - context: context, - builder: (_) => data != null - ? _AlreadyExistsDialog(hwId: hwId) - : _AddCarDialog(hwId: hwId), - ); + if (data != null) { + await showDialog( + context: context, + builder: (_) => _AlreadyExistsDialog(hwId: hwId), + ); + } else { + // Dialog returns true if the car was added successfully. + final added = await showDialog( + 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);