initializeLocalNotification static method
dynamic
initializeLocalNotification({})
Implementation
static initializeLocalNotification(
{void onNotificationPressed(Map<String, dynamic> data)?,
required String icon}) async {
// Create an Android notification Channel.
///
/// We use this channel in the `AndroidManifest.xml` file to override the
/// default FCM channel to enable heads up notifications.
await flutterLocalNotificationsPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings(icon);
final DarwinInitializationSettings initializationSettingsIOS =
DarwinInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification);
final InitializationSettings initializationSettings =
InitializationSettings(
android: initializationSettingsAndroid,
iOS: initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onDidReceiveNotificationResponse: (notificationResponse) {
onDidReceiveNotificationResponse(
notificationResponse: notificationResponse,
onData: onNotificationPressed);
},
);
}