编辑:此问题已在最新的flutter和firebase版本中得到解决。
我正在监听Firebase FCM的data
类型消息,收到FCM消息后,我想从应用程序内显示本地通知。
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on message $message');
LocalNotificationService.showNotoficationWithDefaultSound("onmessage");
},
onResume: (Map<String, dynamic> message) async {
LocalNotificationService.showNotoficationWithDefaultSound("onresume");
print('on resume $message');
},
onLaunch: (Map<String, dynamic> message) async {
LocalNotificationService.showNotoficationWithDefaultSound("onlaunch");
print('on launch $message');
},
onBackgroundMessage: myBackgroundMessageHandler,
);
/// Yes. This is a global function
Future<dynamic> myBackgroundMessageHandler(Map<String, dynamic> message) {
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
'chanID_007', 'chanName_kk107', 'This is my channel');
var iosPlatformChannelSpecifics = new IOSNotificationDetails();
var platformChannelSpecifics = new NotificationDetails(
androidPlatformChannelSpecifics, iosPlatformChannelSpecifics);
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
var initializationSettingsAndroid =
new AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIos = new IOSInitializationSettings();
var initializationSettings = new InitializationSettings(
initializationSettingsAndroid, initializationSettingsIos);
flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
await flutterLocalNotificationsPlugin.show(
0, 'Tada!!', 'test', platformChannelSpecifics,
payload: 'payload#7');
print("background mssg");
}
使用flutter_local_notification插件显示本地通知时出现错误,抛出MissingPluginException异常(在频道dexterous.com/flutter/local_notifications上找不到方法initialize的实现)。我漏了什么?