requestNotificationPermission method

Future<bool> requestNotificationPermission()

Requests notification permissions from the user.

Shows the system permission dialog to the user. On web, this always returns false as web notification permissions are not supported.

Returns:

  • true if the user granted permission, false otherwise

Implementation

Future<bool> requestNotificationPermission() async {
  if (kIsWeb) return false;
  final settings = await _firebaseMessaging.requestPermission(
    alert: true,
    badge: true,
    sound: true,
    carPlay: true,
    provisional: true,
    announcement: true,
    criticalAlert: true,
    providesAppNotificationSettings: false,
  );
  return settings.authorizationStatus == AuthorizationStatus.authorized;
}