diff --git a/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart b/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart index 63bd1e6..264bbbd 100644 --- a/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart +++ b/lib/screens/metering/components/shared/readings_container/components/shared/animated_dialog_picker/components/animated_dialog/widget_dialog_animated.dart @@ -221,7 +221,13 @@ class AnimatedDialogState extends State with SingleTickerProvide }); } - Future close() => _animateReverse().then((_) => Navigator.of(context).pop()); + Future close() { + return _animateReverse().then((_) { + if (mounted) { + Navigator.of(context).pop(); + } + }); + } } class _AnimatedOverlay extends StatelessWidget { diff --git a/lib/screens/metering/screen_metering.dart b/lib/screens/metering/screen_metering.dart index 7771bf2..417d330 100644 --- a/lib/screens/metering/screen_metering.dart +++ b/lib/screens/metering/screen_metering.dart @@ -69,9 +69,14 @@ class MeteringScreen extends StatelessWidget { } void pushNamed(BuildContext context, String routeName, {Object? arguments}) { - context.read().add(const ScreenOnTopOpenedEvent()); - Navigator.pushNamed(context, routeName, arguments: arguments).then((_) { - context.read().add(const ScreenOnTopClosedEvent()); + final bloc = context.read(); + bloc.add(const ScreenOnTopOpenedEvent()); + Navigator.pushNamed( + context, + routeName, + arguments: arguments, + ).then((_) { + bloc.add(const ScreenOnTopClosedEvent()); }); } } diff --git a/lib/screens/settings/components/about/components/write_email/widget_list_tile_write_email.dart b/lib/screens/settings/components/about/components/write_email/widget_list_tile_write_email.dart index aab959f..e5271ff 100644 --- a/lib/screens/settings/components/about/components/write_email/widget_list_tile_write_email.dart +++ b/lib/screens/settings/components/about/components/write_email/widget_list_tile_write_email.dart @@ -4,9 +4,14 @@ import 'package:lightmeter/constants.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:url_launcher/url_launcher.dart'; -class WriteEmailListTile extends StatelessWidget { +class WriteEmailListTile extends StatefulWidget { const WriteEmailListTile({super.key}); + @override + State createState() => _WriteEmailListTileState(); +} + +class _WriteEmailListTileState extends State { @override Widget build(BuildContext context) { return ListTile( @@ -20,24 +25,30 @@ class WriteEmailListTile extends StatelessWidget { mailToUrl, mode: LaunchMode.externalApplication, ); - } else { - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text(S.of(context).youDontHaveMailApp), - behavior: SnackBarBehavior.floating, - action: SnackBarAction( - label: S.of(context).copyEmail, - onPressed: () { - FlutterClipboard.copy(contactEmail).then((_) { - ScaffoldMessenger.of(context).clearSnackBars(); - }); - }, - ), - ), - ); + } else if (mounted) { + _showSnackBar(); } }); }, ); } + + Future _showSnackBar() async { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(S.of(context).youDontHaveMailApp), + behavior: SnackBarBehavior.floating, + action: SnackBarAction( + label: S.of(context).copyEmail, + onPressed: () { + FlutterClipboard.copy(contactEmail).then((_) { + if (mounted) { + ScaffoldMessenger.of(context).clearSnackBars(); + } + }); + }, + ), + ), + ); + } } diff --git a/lib/screens/settings/components/general/components/language/widget_list_tile_language.dart b/lib/screens/settings/components/general/components/language/widget_list_tile_language.dart index 14d8971..b2410b4 100644 --- a/lib/screens/settings/components/general/components/language/widget_list_tile_language.dart +++ b/lib/screens/settings/components/general/components/language/widget_list_tile_language.dart @@ -14,6 +14,7 @@ class LanguageListTile extends StatelessWidget { title: Text(S.of(context).language), trailing: Text(UserPreferencesProvider.localeOf(context).localizedName), onTap: () { + final prefs = UserPreferencesProvider.of(context); showDialog( context: context, builder: (_) => DialogPicker( @@ -21,11 +22,11 @@ class LanguageListTile extends StatelessWidget { title: S.of(context).chooseLanguage, selectedValue: UserPreferencesProvider.localeOf(context), values: SupportedLocale.values, - titleAdapter: (context, value) => value.localizedName, + titleAdapter: (_, value) => value.localizedName, ), ).then((value) { if (value != null) { - UserPreferencesProvider.of(context).setLocale(value); + prefs.setLocale(value); } }); }, diff --git a/lib/screens/settings/components/metering/components/fractional_stops/widget_list_tile_fractional_stops.dart b/lib/screens/settings/components/metering/components/fractional_stops/widget_list_tile_fractional_stops.dart index 90ab875..e97ef13 100644 --- a/lib/screens/settings/components/metering/components/fractional_stops/widget_list_tile_fractional_stops.dart +++ b/lib/screens/settings/components/metering/components/fractional_stops/widget_list_tile_fractional_stops.dart @@ -14,6 +14,7 @@ class StopTypeListTile extends StatelessWidget { title: Text(S.of(context).fractionalStops), trailing: Text(_typeToString(context, UserPreferencesProvider.stopTypeOf(context))), onTap: () { + final prefs = UserPreferencesProvider.of(context); showDialog( context: context, builder: (_) => DialogPicker( @@ -25,7 +26,7 @@ class StopTypeListTile extends StatelessWidget { ), ).then((value) { if (value != null) { - UserPreferencesProvider.of(context).setStopType(value); + prefs.setStopType(value); } }); }, diff --git a/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart b/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart index 6560d4c..1e66074 100644 --- a/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart +++ b/lib/screens/settings/components/theme/components/primary_color/widget_list_tile_primary_color.dart @@ -22,12 +22,13 @@ class PrimaryColorListTile extends StatelessWidget { leading: const Icon(Icons.palette_outlined), title: Text(S.of(context).primaryColor), onTap: () { + final prefs = UserPreferencesProvider.of(context); showDialog( context: context, builder: (_) => const PrimaryColorDialogPicker(), ).then((value) { if (value != null) { - UserPreferencesProvider.of(context).setPrimaryColor(value); + prefs.setPrimaryColor(value); } }); }, diff --git a/lib/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart b/lib/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart index a74464c..07326e5 100644 --- a/lib/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart +++ b/lib/screens/settings/components/theme/components/theme_type/widget_list_tile_theme_type.dart @@ -14,6 +14,7 @@ class ThemeTypeListTile extends StatelessWidget { title: Text(S.of(context).theme), trailing: Text(_typeToString(context, UserPreferencesProvider.themeTypeOf(context))), onTap: () { + final prefs = UserPreferencesProvider.of(context); showDialog( context: context, builder: (_) => DialogPicker( @@ -25,7 +26,7 @@ class ThemeTypeListTile extends StatelessWidget { ), ).then((value) { if (value != null) { - UserPreferencesProvider.of(context).setThemeType(value); + prefs.setThemeType(value); } }); }, diff --git a/lib/screens/shared/release_notes_dialog/flow_dialog_release_notes.dart b/lib/screens/shared/release_notes_dialog/flow_dialog_release_notes.dart index de7af05..fc00ea2 100644 --- a/lib/screens/shared/release_notes_dialog/flow_dialog_release_notes.dart +++ b/lib/screens/shared/release_notes_dialog/flow_dialog_release_notes.dart @@ -21,10 +21,11 @@ class ReleaseNotesFlow extends StatelessWidget { child: BlocListener( listener: (context, state) { if (state is ShowReleaseNotesDialogState) { + final bloc = context.read(); showDialog( context: context, builder: (_) => ReleaseNotesDialog(version: state.version), - ).then((_) => context.read().setChangelogVersion()); + ).then((_) => bloc.setChangelogVersion()); } }, child: child,