[Flutter/dart] Bold notification title with local_notification
Overview
You can easily create notifications using flutter's library called local_notification. This time, I will show you how to make the notification title bold in local_notification. Please refer to the official website for basic usage.
Method
for ios
For ios, it is bold by default.
for Android
For Android, if you do nothing, the title and body will be the same thickness.
Here's how to make the title bold.
Set DefaultStyleInformation () to the styleInformation: property of AndroidNotificationDetails (2) and set htmlFormatTitle to true (1).
var styleInformation=DefaultStyleInformation(true, true); //1
var androidChannelSpecifics = AndroidNotificationDetails(
"channel_id",
"channel_name",
"channel_description",
importance: Importance.max,
priority: Priority.high,
styleInformation: styleInformation, //2
);
If the first item of the DefaultStyleInformation constructor is set to true, the body can be set, and if the second items are set to true, the title can be formatted in html format.
default_style_information.dart
/// The default Android notification style.
class DefaultStyleInformation implements StyleInformation {
/// Constructs an instance of [DefaultStyleInformation].
const DefaultStyleInformation(
this.htmlFormatContent,
this.htmlFormatTitle,
);
/// Specifies if formatting should be applied to the content through HTML
/// markup.
final bool htmlFormatContent;
/// Specifies if formatting should be applied to the title through HTML
/// markup.
final bool htmlFormatTitle;
}
Next, format the title property of the method that creates the notification as follows and pass it.
An example is showWeeklyAtDayAndTime (), but the same is true for other methods.
await flutterLocalNotificationsPlugin.showWeeklyAtDayAndTime(
id,
Platform.isAndroid? '<b>${title}</b>': title, //here!
content,
day,
time,
platformChannelSpecifics,
payload: payload,
);
In the case of ios, the format is not applied, so it depends on whether the platform is android or not.
Lastly
Is it possible to format other than bold? I don't know because I haven't tried it.
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...
Comentários