How to show more than one line in a notification message (flutter_local_notifications package)

僤鯓⒐⒋嵵緔 提交于 2020-05-31 10:14:48

问题


I have a problem that only the first line in the notification body appears, how can I make the notification expanded with large content?

This is the code, using the flutter_local_notifications package:

void showNotification(int id, String title, String content, DateTime time) async {
  final AndroidNotificationDetails android = AndroidNotificationDetails(
      'ch_ID', 'Ch_Name', 'ch_Description', 
      priority: Priority.High, importance: Importance.Max);
  final IOSNotificationDetails ios = IOSNotificationDetails();
  final NotificationDetails platform = NotificationDetails(android, ios);

  await flutterLocalNotificationsPlugin.schedule(
      id,
      '$title',
      '$content',
      time,
      platform,
      payload: 'payload'
  );
}


回答1:


As mentioned in a comment in this other very similar StackOverflow question, you can set the styleInformation parameter with other classes to format your text. One of these is BigTextStyleInformation, which implements the DefaultTextStyleInformation, which is also an implementation of the abstract class StyleInformation.

final AndroidNotificationDetails android = AndroidNotificationDetails(
  'ch_ID',
  'Ch_Name',
  'ch_Description',
  priority: Priority.High,
  importance: Importance.Max,

  // add this line in your code
  styleInformation: BigTextStyleInformation(''),
);


来源:https://stackoverflow.com/questions/61156520/how-to-show-more-than-one-line-in-a-notification-message-flutter-local-notifica

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!