init method

  1. @mustCallSuper
Future<bool?> init({
  1. String? appIcon,
  2. DateTime? schedule,
  3. String? title,
  4. String? body,
  5. String? payload,
  6. bool? androidAllowWhileIdle,
  7. String? icon,
  8. Importance? importance,
  9. Priority? priority,
  10. StyleInformation? styleInformation,
  11. bool? playSound,
  12. AndroidNotificationSound? sound,
  13. bool? enableVibration,
  14. List<int>? vibrationPattern,
  15. String? groupKey,
  16. bool? setAsGroupSummary,
  17. GroupAlertBehavior? groupAlertBehavior,
  18. bool? autoCancel,
  19. bool? ongoing,
  20. Color? color,
  21. AndroidBitmap<Object>? largeIcon,
  22. bool? onlyAlertOnce,
  23. bool? showWhen,
  24. int? when,
  25. bool? usesChronometer,
  26. bool? channelShowBadge,
  27. bool? showProgress,
  28. int? maxProgress,
  29. int? progress,
  30. bool? indeterminate,
  31. AndroidNotificationChannelAction? channelAction,
  32. bool? enableLights,
  33. Color? ledColor,
  34. int? ledOnMs,
  35. int? ledOffMs,
  36. String? ticker,
  37. NotificationVisibility? visibility,
  38. int? timeoutAfter,
  39. String? category,
  40. bool? fullScreenIntent,
  41. String? shortcutId,
  42. Int32List? additionalFlags,
  43. String? subText,
  44. String? tag,
  45. RepeatInterval? repeatInterval,
  46. Day? day,
  47. Time? notificationTime,
  48. SelectNotificationCallback? onSelectNotification,
  49. bool? requestAlertPermission,
  50. bool? requestSoundPermission,
  51. bool? requestBadgePermission,
  52. bool? defaultPresentAlert,
  53. bool? defaultPresentSound,
  54. bool? defaultPresentBadge,
  55. DidReceiveLocalNotificationCallback? onDidReceiveLocalNotification,
  56. bool? presentAlert,
  57. bool? presentSound,
  58. bool? presentBadge,
  59. String? soundFile,
  60. int? badgeNumber,
  61. List<IOSNotificationAttachment>? attachments,
  62. String? subtitle,
  63. String? threadIdentifier,
})

Initialize the App's Notification system.

Implementation

@mustCallSuper
Future<bool?> init({
  String? appIcon,
  DateTime? schedule,
  String? title,
  String? body,
  String? payload,
  bool? androidAllowWhileIdle,
  String? icon,
  Importance? importance,
  Priority? priority,
  StyleInformation? styleInformation,
  bool? playSound,
  AndroidNotificationSound? sound,
  bool? enableVibration,
  List<int>? vibrationPattern,
  String? groupKey,
  bool? setAsGroupSummary,
  GroupAlertBehavior? groupAlertBehavior,
  bool? autoCancel,
  bool? ongoing,
  Color? color,
  AndroidBitmap<Object>? largeIcon,
  bool? onlyAlertOnce,
  bool? showWhen,
  int? when,
  bool? usesChronometer,
  bool? channelShowBadge,
  bool? showProgress,
  int? maxProgress,
  int? progress,
  bool? indeterminate,
  AndroidNotificationChannelAction? channelAction,
  bool? enableLights,
  Color? ledColor,
  int? ledOnMs,
  int? ledOffMs,
  String? ticker,
  NotificationVisibility? visibility,
  int? timeoutAfter,
  String? category,
  bool? fullScreenIntent,
  String? shortcutId,
  Int32List? additionalFlags,
  String? subText,
  String? tag,
  RepeatInterval? repeatInterval,
  Day? day,
  Time? notificationTime,
  SelectNotificationCallback? onSelectNotification,
  bool? requestAlertPermission,
  bool? requestSoundPermission,
  bool? requestBadgePermission,
  bool? defaultPresentAlert,
  bool? defaultPresentSound,
  bool? defaultPresentBadge,
  DidReceiveLocalNotificationCallback? onDidReceiveLocalNotification,
  bool? presentAlert,
  bool? presentSound,
  bool? presentBadge,
  String? soundFile,
  int? badgeNumber,
  List<IOSNotificationAttachment>? attachments,
  String? subtitle,
  String? threadIdentifier,
}) async {
  // No need to continue.
  if (_init!) {
    return _init;
  }

  if (appIcon != null && appIcon.trim().isEmpty) {
    appIcon = null;
  }
  appIcon ??= _appIcon;
  // init parameters take over initial parameter values.
  if (schedule != null) {
    _schedule = schedule;
  }
  if (title != null) {
    _title = title;
  }
  if (body != null) {
    _body = body;
  }
  if (payload != null) {
    _payload = payload;
  }
  if (androidAllowWhileIdle != null) {
    _androidAllowWhileIdle = androidAllowWhileIdle;
  }
  if (icon != null) {
    _icon = icon;
  }
  if (importance != null) {
    _importance = importance;
  }
  if (priority != null) {
    _priority = priority;
  }
  if (styleInformation != null) {
    _styleInformation = styleInformation;
  }
  if (playSound != null) {
    _playSound = playSound;
  }
  if (sound != null) {
    _sound = sound;
  }
  if (enableVibration != null) {
    _enableVibration = enableVibration;
  }
  if (vibrationPattern != null) {
    _vibrationPattern = vibrationPattern;
  }
  if (groupKey != null) {
    _groupKey = groupKey;
  }
  if (setAsGroupSummary != null) {
    _setAsGroupSummary = setAsGroupSummary;
  }
  if (groupAlertBehavior != null) {
    _groupAlertBehavior = groupAlertBehavior;
  }
  if (autoCancel != null) {
    _autoCancel = autoCancel;
  }
  if (ongoing != null) {
    _ongoing = ongoing;
  }
  if (color != null) {
    _color = color;
  }
  if (largeIcon != null) {
    _largeIcon = largeIcon;
  }
  if (onlyAlertOnce != null) {
    _onlyAlertOnce = onlyAlertOnce;
  }
  if (showWhen != null) {
    _showWhen = showWhen;
  }
  if (when != null) {
    _when = when;
  }
  if (usesChronometer != null) {
    _usesChronometer = usesChronometer;
  }
  if (channelShowBadge != null) {
    _channelShowBadge = channelShowBadge;
  }
  if (showProgress != null) {
    _showProgress = showProgress;
  }
  if (maxProgress != null) {
    _maxProgress = maxProgress;
  }
  if (progress != null) {
    _progress = progress;
  }
  if (indeterminate != null) {
    _indeterminate = indeterminate;
  }
  if (channelAction != null) {
    _channelAction = channelAction;
  }
  if (enableLights != null) {
    _enableLights = enableLights;
  }
  if (ledColor != null) {
    _ledColor = ledColor;
  }
  if (ledOnMs != null) {
    _ledOnMs = ledOnMs;
  }
  if (ledOffMs != null) {
    _ledOffMs = ledOffMs;
  }
  if (ticker != null) {
    _ticker = ticker;
  }
  if (visibility != null) {
    _visibility = visibility;
  }
  if (timeoutAfter != null) {
    _timeoutAfter = timeoutAfter;
  }
  if (category != null) {
    _category = category;
  }
  if (fullScreenIntent != null) {
    _fullScreenIntent = fullScreenIntent;
  }
  if (shortcutId != null) {
    _shortcutId = shortcutId;
  }
  if (additionalFlags != null) {
    _additionalFlags = additionalFlags;
  }
  if (subText != null) {
    _subText = subText;
  }
  if (tag != null) {
    _tag = tag;
  }
  if (day != null) {
    _day = day;
  }
  onSelectNotification ??=
      _selectNotificationCallback ?? _onSelectNotification;
  requestAlertPermission ??= _requestAlertPermission;
  requestSoundPermission ??= _requestSoundPermission;
  requestBadgePermission ??= _requestBadgePermission;
  defaultPresentAlert ??= _defaultPresentAlert;
  defaultPresentSound ??= _defaultPresentSound;
  defaultPresentBadge ??= _defaultPresentBadge;
  onDidReceiveLocalNotification ??= _onDidReceiveLocalNotification;
  if (presentAlert != null) {
    _presentAlert = presentAlert;
  }
  if (presentSound != null) {
    _presentSound = presentSound;
  }
  if (presentBadge != null) {
    _presentBadge = presentBadge;
  }
  if (soundFile != null) {
    _soundFile = soundFile;
  }
  if (badgeNumber != null) {
    _badgeNumber = badgeNumber;
  }
  if (attachments != null) {
    _attachments = attachments;
  }
  if (subtitle != null) {
    _subtitle = subtitle;
  }
  if (threadIdentifier != null) {
    _threadIdentifier = threadIdentifier;
  }
  //
  try {
    final initializationSettingsIOS = IOSInitializationSettings(
      requestAlertPermission: requestAlertPermission!,
      requestBadgePermission: requestSoundPermission!,
      requestSoundPermission: requestBadgePermission!,
      defaultPresentAlert: defaultPresentAlert!,
      defaultPresentSound: defaultPresentSound!,
      defaultPresentBadge: defaultPresentBadge!,
      onDidReceiveLocalNotification: onDidReceiveLocalNotification ??
          ((int id, String? title, String? body, String? payload) =>
              onSelectNotification!(payload)),
    );

    WidgetsFlutterBinding.ensureInitialized();

    final initializationSettings = InitializationSettings(
      android: AndroidInitializationSettings(_appIcon!),
      iOS: initializationSettingsIOS,
    );

    _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

    _init = await _flutterLocalNotificationsPlugin!.initialize(
        initializationSettings,
        onSelectNotification: onSelectNotification);
  } catch (ex) {
    getError(ex);
    _init = false;
  }
  return _init;
}