requestPermissions static method

Future<void> requestPermissions({
  1. bool alert = true,
  2. bool badge = true,
  3. bool sound = true,
  4. bool provisional = false,
  5. bool critical = false,
  6. bool vibrate = true,
  7. bool enableLights = true,
  8. String channelId = "default_notification_channel_id",
  9. String channelName = "Default Notification Channel",
  10. String? description,
  11. String? groupId,
  12. Importance? importance,
  13. List<int>? vibratePattern,
  14. Color? ledColor,
  15. AudioAttributesUsage? audioAttributesUsage,
})

Request permissions

Implementation

static Future<void> requestPermissions({
  bool alert = true,
  bool badge = true,
  bool sound = true,
  bool provisional = false,
  bool critical = false,
  bool vibrate = true,
  bool enableLights = true,
  String channelId = "default_notification_channel_id",
  String channelName = "Default Notification Channel",
  String? description,
  String? groupId,
  Importance? importance,
  List<int>? vibratePattern,
  Color? ledColor,
  AudioAttributesUsage? audioAttributesUsage,
}) async {
  if (kIsWeb) {
    throw Exception("Push notifications are not supported on the web");
  }
  await Nylo.localNotifications(
      (FlutterLocalNotificationsPlugin localNotifications) async {
    if (Platform.isIOS) {
      await localNotifications
          .resolvePlatformSpecificImplementation<
              IOSFlutterLocalNotificationsPlugin>()
          ?.requestPermissions();
      return;
    }
    if (Platform.isAndroid) {
      await localNotifications
          .resolvePlatformSpecificImplementation<
              AndroidFlutterLocalNotificationsPlugin>()
          ?.requestNotificationsPermission();
      return;
    }

    throw Exception("Platform not supported");
  });
}