checkNotificationPermission method
Checks if the user has given permission to send notifications.
If the user has not given permission, this function will ask for permission.
Implementation
Future<bool> checkNotificationPermission() async {
if (Platform.isAndroid) {
return await androidImplementation!
.areNotificationsEnabled()
.then((granted) async {
if (granted != null && granted) return true;
return Future.wait([
androidImplementation!.requestNotificationsPermission(),
androidImplementation!.requestExactAlarmsPermission(),
androidImplementation!.requestExactAlarmsPermission(),
]).then((value) => value.every((element) => element == true));
});
} else if (Platform.isIOS) {
return await iosImplementation!
.requestPermissions(
alert: true,
badge: true,
sound: true,
)
.then((granted) => granted == true);
} else {
return false;
}
}