top of page

[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 All

Comments


Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png
bottom of page