android_notifications 1.0.0 android_notifications: ^1.0.0 copied to clipboard
A Flutter plugin for managing notification on Android Platform.
android_notifications #
A Flutter plugin for managing notification on Android Platform.
Usage: #
- Create a notification.
AndroidNotification notification = const AndroidNotification(
contentTitle: 'From Flutter',
contentText: 'Hello, Android, I am Flutter.'
);
- Posts a notification to be shown in the status bar (async).
AndroidNotificationManager _manager = const AndroidNotificationManager();
static const int _notificationId = 1;
void notify(AndroidNotification notification) async {
await _manager.notify(_notificationId, notification);
}
- Cancel a previously shown notification (async).
AndroidNotificationManager _manager = const AndroidNotificationManager();
static const int _notificationId = 1;
void cancel() async {
await _manager.cancel(_notificationId);
}
About small icon #
To create Notification in Android, you must set the small icon by setSmallIcon()
, Otherwise it will throw an exception(error, Invalid notification (no valid small icon)), The small icon resource used by this plugin by default is {your_package_name}.R.mipmap.ic_launcher, if you do not want to use it as a notification icon, please register the plugin manually and set the small icon in the following way.
class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
val plugin = AndroidNotificationsPlugin(smallIcon = R.mipmap.ic_launcher)
flutterEngine.plugins.add(plugin)
}
}