Android Studio 如何在Flutter通知中使用HTML代码?

hjqgdpho  于 2022-11-16  发布在  Android
关注(0)|答案(1)|浏览(120)

我今天刚开始做Flutter
我想在Android通知中使用HTML代码。
似乎通过将DefaultStyleInformation参数设置为true,可以使用HTML,但我不知道如何编写实际的代码。
//这是提供的界面。

/// 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;
}

下面是我正在写的代码。我觉得我需要关于“//here”部分的帮助。

import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'dart:io'; 

 Future<void> showBigTextNotification() async {
    const styleInformation=DefaultStyleInformation(true,true);
    const NotificationDetails notificationDetails = 
    NotificationDetails(
      android: AndroidNotificationDetails(
       'channel_id',
       'Channel Name',
       importance: Importance.max,
       priority: Priority.high,
       styleInformation: styleInformation
       ),
       iOS: IOSNotificationDetails());

    await flutterLocalNotificationsPlugin.show(
      id, 
      Platform.isAndroid? '<b>'${title}'</b>': title,     // here???
      Platform.isAndroid? '<b>'${content}'</b>': content, // here???
      payload: 'Destination Screen(Big Text Notification)');
  }

thanks.
zsbz8rwp

zsbz8rwp1#

你的问题是在bigTextInformation样式和一些东西是丢失请使用下面的代码现在将html文本转换为常规文本

Future<void> showBigTextNotification() async {
        BigTextStyleInformation bigTextStyleInformation = BigTextStyleInformation(
          body, htmlFormatBigText: true,
          htmlFormatTitle:true ,
          htmlFormatContent:true ,
                contentTitle: 'overridden <b>big</b> content title',
                htmlFormatContentTitle: true,
                summaryText: 'summary <i>text</i>',
                htmlFormatSummaryText: true
    
        );
  final androidChannelSpecifics = AndroidNotificationDetails(
    'your channel id',
    'your channel name',
    importance: Importance.max,
    styleInformation: bigTextStyleInformation,
    priority: Priority.high,
    ongoing: true,
    autoCancel: true,
  );
 final iOSChannelSpecifics = IOSNotificationDetails();

   NotificationDetails platformChannelSpecifics =  NotificationDetails(android: androidChannelSpecifics, iOS: iOSChannelSpecifics);
    
        await flutterLocalNotificationsPlugin.show(
          id, 
          Platform.isAndroid? '<b>'${title}'</b>': title,     // here???
          Platform.isAndroid? '<b>'${content}'</b>': content, // here???
          type: platformChannelSpecifics,
          payload: 'Destination Screen(Big Text Notification)');
      }

相关问题