I started Flutter exactly today.
I want to use HTML code within Android notifications.
It seems that by setting the DefaultStyleInformation argument to true, HTML can be used, but I don’t know how to write the actual code.
//This is the interface provided.
/// 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;
}
The following is the code I am writing.
I feel I need help with the "//here" part.
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.
2
Answers
Simply use
BigTextStyleInformation
to show html content in notifications