Skip to content

Commit

Permalink
Merge branch 'main' into rehan/mbl-455-native-sdk-update
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Sep 4, 2024
2 parents 3828bac + aa5af46 commit 78ef900
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ internal fun <R> MethodCall.invokeNative(
try {
@Suppress("UNCHECKED_CAST")
val params = this.arguments as? Map<String, Any> ?: emptyMap()
result.success(performAction(params))
val actionResult = performAction(params)
if (actionResult is Unit) {
result.success(true)
} else {
result.success(actionResult)
}
} catch (ex: Exception) {
result.error(this.method, ex.localizedMessage, ex)
}
Expand Down
8 changes: 6 additions & 2 deletions apps/amiapp_flutter/lib/src/screens/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
20 changes: 13 additions & 7 deletions apps/amiapp_flutter/lib/src/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
super.initState();
}

void _saveSettings() {
void _saveSettings(BuildContext context) {
if (!_formKey.currentState!.validate()) {
return;
}
Expand All @@ -88,7 +88,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
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
Expand Down Expand Up @@ -118,7 +120,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
_featureTrackDeviceAttributes =
defaultConfig.deviceAttributesTrackingEnabled;
_featureDebugMode = defaultConfig.debugModeEnabled;
_saveSettings();
_saveSettings(context);
});
}

Expand All @@ -127,7 +129,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
final Sizes sizes = Theme.of(context).extension<Sizes>()!;

return PopScope(
onPopInvoked: (bool didPop) {
onPopInvokedWithResult: (bool didPop, result) {
if (widget.auth.signedIn == false) {
context.go(Screen.login.location);
}
Expand Down Expand Up @@ -166,9 +168,13 @@ class _SettingsScreenState extends State<SettingsScreen> {
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',
);
}
});
},
),
),
Expand Down Expand Up @@ -284,7 +290,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
style: FilledButton.styleFrom(
minimumSize: sizes.buttonDefault(),
),
onPressed: () => _saveSettings(),
onPressed: () => _saveSettings(context),
child: Text(
'Save'.toUpperCase(),
semanticsLabel: 'Save Settings Button',
Expand Down

0 comments on commit 78ef900

Please sign in to comment.