我尝试在我已经使用过的 Flutter 应用程序中显示通知 FlutterLocalNotificationPlugin
//这是函数初始化
FlutterLocalNotificationsPlugin localNotificationsPlugin;
Future showNotification() async {
var androidDetails = new AndroidNotificationDetails(
"channelId",
"channelName",
"channelDescription",
importance: Importance.max,
priority: Priority.high,
playSound: true,
largeIcon: DrawableResourceAndroidBitmap('tele_marketing'),
);
var iosDetails = new IOSNotificationDetails(
//sound: 'bells.mp3',
presentAlert: true,
presentBadge: true,
presentSound: true);
var generalNotification =
new NotificationDetails(android: androidDetails, iOS: iosDetails);
await localNotificationsPlugin.show(
0, "Total Leads", totalLeads.toString(), generalNotification);
}
// 这是函数调用
@override
void initState() {
super.initState();
//Build Notification in IOS and Android
var androidNotification =
new AndroidInitializationSettings('tele_marketing');
var iosNotification = new IOSInitializationSettings(
requestAlertPermission: true,
requestBadgePermission: true,
requestSoundPermission: true,
);
var notification = new InitializationSettings(
android: androidNotification, iOS: iosNotification);
localNotificationsPlugin = new FlutterLocalNotificationsPlugin();
localNotificationsPlugin.initialize(notification);
}
//调用API时显示功能应用是打开还是关闭
if (snapshot.hasData) {
if (totalLeads > totLeads) {
playSound();
showNotification();
totLeads = totalLeads;
} else {}