【问题标题】:Multi-line push notification flutter多行推送通知颤动
【发布时间】:2020-12-11 01:06:58
【问题描述】:

我正在使用 flutter_local_notifications 包进行推送通知。但是在通知托盘中,我想显示完整的消息,无论它需要多少行。这是我写的代码

void showNotification(message) async {
    var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
      Platform.isAndroid ? 'com.headstrt.app' : 'com.headstrt.app',
      'Flutter chat demo',
      'your channel description',
      playSound: true,
      enableVibration: true,
      importance: Importance.Max,
      priority: Priority.High,
      styleInformation: BigTextStyleInformation(''),
    );

我也指定了一个样式,但仍然没有显示所有行。

【问题讨论】:

  • 尝试在BigTextStyleInformation('')中提供全文?
  • 它实际上是这样显示的

标签: flutter dart


【解决方案1】:

在 BigTextStyleInformation 中,您必须指定传递给 showNotification 函数的消息值。

以我自己的代码为例;

  Future<void> _demoNotification(Map<String, dynamic> icerik) async {

  String longdata = icerik["notification"]["body"];

  var bigTextStyleInformation = BigTextStyleInformation(longdata); //multi-line show style

 AndroidNotificationDetails androidPlatformChannelSpecifics =
 AndroidNotificationDetails(

        'push_messages: 0',
        'push_messages: push_messages',
        'push_messages: A new Flutter project',
        importance: Importance.max,
        priority: Priority.high,
        showWhen: false,
        enableVibration: true,
        styleInformation: bigTextStyleInformation);

NotificationDetails platformChannelSpecifics =
NotificationDetails(android: androidPlatformChannelSpecifics);

await flutterLocalNotificationsPlugin.show(
    1,
    icerik["notification"]["title"],
    icerik["notification"]["body"],
    platformChannelSpecifics,
    payload: icerik['data']['routing']);

    }

【讨论】:

  • 请注意,通知的标题总是单行的,并且也可能由于图标或时间信息(例如5min ago)而被截断。我们发现,将标题限制为 30 个字符几乎总能确保永远不会被截断(但根据语言的不同,极值是 11 个字符)。
【解决方案2】:

这实际上并不取决于您。在 Android 中,单个通知的默认设置是在线的。如果您想查看整个消息,您需要向下拖动通知。

【讨论】:

  • 它不起作用。我无法向下拖动通知。
猜你喜欢
  • 2021-01-25
  • 2020-06-26
  • 2022-08-11
  • 2021-11-04
  • 2021-12-28
  • 2021-06-30
  • 2020-03-19
  • 2021-12-29
  • 1970-01-01
相关资源
最近更新 更多