[Flutter/dart] Display an icon on the notification screen with local_notification
Overview
You can create notifications using a library called local_notification. The official sample only has a title and body, but you can also add an icon like Line. This time, I will introduce how to display the icon on the notification screen.
Method
For android
set largeIcon property of AndroidNotificationDetails()
var styleInformation=DefaultStyleInformation(true, true);
var androidChannelSpecifics = AndroidNotificationDetails(
"channel_id",
"channel_name",
"channel_description",
importance: Importance.max,
priority: Priority.high,
largeIcon: FilePathAndroidBitmap(icon_path), //here!
styleInformation: styleInformation,
);
In my case, the icon image is saved locally, so I pass the image path (icon_path) to the argument of FilePathAndroidBitmap (). If you want to use the image in drawable resource, you can use DrawableResourceAndroidBitmap () (as far as I read the docs, I haven't tried it).
for ios
Do the following: icon_path is the path of the icon image.
var iosChannelSpecifics =IOSNotificationDetails(
attachments: [IOSNotificationAttachment(icon_path)]
);
It should be noted that the image placed in icon_path will be moved by the system after creating the notification. If you're referencing icon_path anywhere other than creating a notification, make sure to copy the file and pass in that path.
Once validated, attached files are moved into the attachment data store so that they can be accessed by all of the appropriate processes.
Finally, create a platformChannelSpecific with the androidChannelSpecific and isoChannelSpecific created above as arguments.
var platformChannelSpecifics =
NotificationDetails(
android: androidChannelSpecifics,
iOS: iosChannelSpecifics
);
The notification screen is as follows. (It's ios)
Lastly
It seems that you can't bring an icon in front of the title like Line (please let me know if you can!).
Recent Posts
See AllWhat want to do I want to create an input form using TextField. For example, if the input content is a monetary amount, I would like to...
What want to do There is a variable that remain unchanged once the initial value is determined. However, it cannot be determined yet when...
What want to do As the title suggests. Place two widgets in one line on the screen One in the center of the screen and the other on the...
Comments