GitHub - mitchhymel/local_notifications: Flutter plugin for creating notificatio...
source link: https://github.com/mitchhymel/local_notifications
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
local_notifications
A Flutter plugin for local notifications for Android and iOS. Available on Pub.
Usage
See the full example here
Features supported by platform
Feature Android iOS 10+ 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 tag of your manifest (android\app\src\main\AndroidManifest.xml)
<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(
title: 'Basic',
content: 'some basic notification',
);
Creating a notification with an image
int id = await LocalNotifications.createNotification(
title: 'Image',
content: 'some notification with an image',
imageUrl: _imageUrl,
);
Creating an undismissable notification
int id = await LocalNotifications.createNotification(
title: 'No swiping',
content: 'Can\'t swipe this away',
imageUrl: _imageUrl,
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(
title: 'Callback and payload notif',
content: 'Some content',
onNotificationClick: new NotificationAction(
actionText: "some action", // Note: action text gets ignored here, as android can't display this anywhere
callback: onNotificationClick,
payload: "some payload"
),
);
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.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK