init method
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,
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;
}