local_notifications 0.0.1 local_notifications: ^0.0.1 copied to clipboard
A flutter plugin for creating local notifications.
local_notifications #
A Flutter plugin for showing and removing notifications.
Usage #
See the full example here
Features supported by platform #
Feature | Android | ios |
---|---|---|
Create local notification with custom title and content |
|
|
Create local notification with custom actions with custom callbacks |
|
|
Dismiss local notification which is already delivered |
|
|
Create local notification with an image |
|
|
Create local notification which is undismissable |
|
|
Android set up steps #
To have the notification run code in the background (on click of either the notification itself or its actions), you must add the LocalNotificationsService to your app's manifest. Add the following to the
<service
android:name="com.mythichelm.localnotifications.LocalNotificationsService"
android:exported="false" />
Examples #
Creating a basic notification with title and text content #
int id = await LocalNotifications.createNotification(
'Basic', 'some basic notification',
);
Creating a notification with an image #
int id = await LocalNotifications.createNotification(
'Image', 'some notification with an image',
imageUrl: 'https://flutter.io/images/catalog-widget-placeholder.png',
);
Creating an undismissable notification #
int id = await LocalNotifications.createNotification(
'Title', 'content',
imageUrl: 'https://flutter.io/images/catalog-widget-placeholder.png',
isOngoing: true
);
Removing a notification #
await LocalNotifications.removeNotification(id);
Creating a notification that will run code in background on click #
onNotificationClick(String payload) {
// payload is 'some payload'
print('Running in background and received payload: $payload');
}
int id = await LocalNotifications.createNotification(
'Some title',
'Some content',
onNotificationClick: new NotificationAction(
"this_is_ignored", // title of action is ignored for notification click
onNotificationClick, // your callback
"some payload",
launchesApp: false
),
);
Creating a notification with multiple actions, some run in background, some bring app to foreground #
For code, see the example.
Getting Started #
For help getting started with Flutter, view our online documentation.
For help on editing plugin code, view the documentation.