initialize method
- InitializationSettings initializationSettings, {
- SelectNotificationCallback? onSelectNotification,
Initializes the plugin.
Call this method on application before using the plugin further.
Will return a bool value to indicate if initialization succeeded. On iOS this is dependent on if permissions have been granted to show notification When running in environment that is neither Android and iOS (e.g. when running tests), this will be a no-op and return true.
Note that on iOS, initialisation may also request notification permissions where users will see a permissions prompt. This may be fine in cases where it's acceptable to do this when the application runs for the first time. However, if your application needs to do this at a later point in time, set the IOSInitializationSettings.requestAlertPermission, IOSInitializationSettings.requestBadgePermission and IOSInitializationSettings.requestSoundPermission values to false. IOSFlutterLocalNotificationsPlugin.requestPermissions can then be called to request permissions when needed.
To handle when a notification launched an application, use getNotificationAppLaunchDetails.
Implementation
Future<bool?> initialize(
InitializationSettings initializationSettings, {
SelectNotificationCallback? onSelectNotification,
}) async {
if (kIsWeb) {
return true;
}
if (_platform.isAndroid) {
return resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.initialize(initializationSettings.android!,
onSelectNotification: onSelectNotification);
} else if (_platform.isIOS) {
return await resolvePlatformSpecificImplementation<
IOSFlutterLocalNotificationsPlugin>()
?.initialize(initializationSettings.iOS!,
onSelectNotification: onSelectNotification);
} else if (_platform.isMacOS) {
return await resolvePlatformSpecificImplementation<
MacOSFlutterLocalNotificationsPlugin>()
?.initialize(initializationSettings.macOS!,
onSelectNotification: onSelectNotification);
}
return true;
}