【发布时间】:2020-06-13 17:41:03
【问题描述】:
我已经尝试使用 Flutter 实现 Firebase 云消息传递,直到我使用“本地通知”插件来显示通知时我才成功
我的通知在前台工作正常,但在后台显示此错误:
[错误:flutter/lib/ui/ui_dart_state.cc(157)] 未处理的异常: MissingPluginException(找不到方法显示的实现 频道 dexterous.com/flutter/local_notifications)
我使用 Firebase Cloud Messaging 6.0.9、本地通知 1.2.0+4 和最新的 Flutter
这是我的代码: NotificationHandler
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
class NotificationHandler{
static final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); // make it a static field of the class
static void initNotification()
{
// initialise the plugin. app_icon needs to be a added as a drawable resource to the Android head project
var initializationSettingsAndroid = AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIOS = IOSInitializationSettings(
onDidReceiveLocalNotification: onDidReceiveLocalNotification);
var initializationSettings = InitializationSettings(
initializationSettingsAndroid, initializationSettingsIOS);
flutterLocalNotificationsPlugin.initialize(initializationSettings,
onSelectNotification: onSelectNotification);
}
static Future onSelectNotification(String payload) async {
if (payload != null) {
print('notification payload: ' + payload);
}
}
static Future onDidReceiveLocalNotification(int id, String title, String body, String payload) {
print(title+" "+body);
}
}
ShowNotification 方法
static void showNotification(data, data2) async {
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
'dexterous.com.flutter.local_notifications', 'your channel name', 'your channel description',
importance: Importance.Max,
priority: Priority.High);
var iOSPlatformChannelSpecifics =
new IOSNotificationDetails();
var platformChannelSpecifics = new NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await NotificationHandler.flutterLocalNotificationsPlugin
.show(
0,
data,
data2,
platformChannelSpecifics,
payload: 'Custom_Sound',
);
}
【问题讨论】:
-
按照以下步骤操作 1) 使用 flutter clean 命令 2) 卸载以前的应用程序 3) 重新安装应用程序
-
谢谢,问题已解决。这一步没用:(
标签: firebase flutter flutter-dependencies localnotification