allowNotificationGuard function
Implementation
Future<bool> allowNotificationGuard(BuildContext context, String reason) async {
if (await AwesomeNotifications().isNotificationAllowed()) {
return true;
} else {
bool? willAsk = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text(S.of(context).allowNotifications),
content: Text(reason),
actions: [
TextButton(
child: Text(S.of(context).cancel),
onPressed: () => Navigator.of(context).pop(false),
),
TextButton(
child: Text(S.of(context).allow),
onPressed: () async {
Navigator.of(context).pop(true);
},
),
],
));
if (willAsk == true) {
await AwesomeNotifications().requestPermissionToSendNotifications();
return await allowNotificationGuard(
context, S.of(context).didYouMisclick + ' ' + reason);
} else {
return false;
}
}
}