diff --git a/apps/amiapp_flutter/lib/src/screens/dashboard.dart b/apps/amiapp_flutter/lib/src/screens/dashboard.dart index 4640f86..42ee056 100644 --- a/apps/amiapp_flutter/lib/src/screens/dashboard.dart +++ b/apps/amiapp_flutter/lib/src/screens/dashboard.dart @@ -183,7 +183,9 @@ class _ActionList extends StatelessWidget { void _showPushPermissionStatus(BuildContext context) { Permission.notification.status.then((status) { - if (status.isGranted) { + if (!context.mounted) { + return; + } else if (status.isGranted) { context.showMessageDialog(_pushPermissionAlertTitle, 'Push notifications are enabled on this device'); } else if (status.isDenied) { @@ -196,7 +198,9 @@ class _ActionList extends StatelessWidget { void _requestPushPermission(BuildContext context) { Permission.notification.request().then((status) { - if (status.isGranted) { + if (!context.mounted) { + return; + } else if (status.isGranted) { context.showSnackBar('Push notifications are enabled on this device'); } else { _onPushPermissionPermanentlyDenied(context); diff --git a/apps/amiapp_flutter/lib/src/screens/settings.dart b/apps/amiapp_flutter/lib/src/screens/settings.dart index 39da909..5899d82 100644 --- a/apps/amiapp_flutter/lib/src/screens/settings.dart +++ b/apps/amiapp_flutter/lib/src/screens/settings.dart @@ -70,7 +70,7 @@ class _SettingsScreenState extends State { super.initState(); } - void _saveSettings() { + void _saveSettings(BuildContext context) { if (!_formKey.currentState!.validate()) { return; } @@ -88,7 +88,9 @@ class _SettingsScreenState extends State { debugModeEnabled: _featureDebugMode, ); widget._customerIOSDK.saveConfigToPreferences(newConfig).then((success) { - if (success) { + if (!context.mounted) { + return; + } else if (success) { context.showSnackBar('Settings saved successfully'); Navigator.of(context).pop(); // Restart app here @@ -118,7 +120,7 @@ class _SettingsScreenState extends State { _featureTrackDeviceAttributes = defaultConfig.deviceAttributesTrackingEnabled; _featureDebugMode = defaultConfig.debugModeEnabled; - _saveSettings(); + _saveSettings(context); }); } @@ -127,7 +129,7 @@ class _SettingsScreenState extends State { final Sizes sizes = Theme.of(context).extension()!; return PopScope( - onPopInvoked: (bool didPop) { + onPopInvokedWithResult: (bool didPop, result) { if (widget.auth.signedIn == false) { context.go(Screen.login.location); } @@ -166,9 +168,13 @@ class _SettingsScreenState extends State { onPressed: () { final clipboardData = ClipboardData( text: _deviceTokenValueController.text); - Clipboard.setData(clipboardData).then((_) => + Clipboard.setData(clipboardData).then((_) { + if (context.mounted) { context.showSnackBar( - 'Device Token copied to clipboard')); + 'Device Token copied to clipboard', + ); + } + }); }, ), ), @@ -284,7 +290,7 @@ class _SettingsScreenState extends State { style: FilledButton.styleFrom( minimumSize: sizes.buttonDefault(), ), - onPressed: () => _saveSettings(), + onPressed: () => _saveSettings(context), child: Text( 'Save'.toUpperCase(), semanticsLabel: 'Save Settings Button',