首页 > 解决方案 > 多行推送通知颤动

问题描述

我正在使用 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(''),
    );

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

在此处输入图像描述

标签: flutterdart

解决方案


在 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']);

    }

推荐阅读