gpt4 book ai didi

firebase - MissingPluginException(在 channel dexterous.com/flutter/local_notifications 上找不到方法显示的实现)

转载 作者:行者123 更新时间:2023-12-03 13:30:32 26 4
gpt4 key购买 nike

我已经尝试使用 Flutter 实现 Firebase Cloud Messaging,并且在我使用“本地通知”插件显示通知之前我是成功的

我的通知在前台工作正常,但在后台显示此错误:

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method show on channel dexterous.com/flutter/local_notifications)



我使用 Firebase Cloud Messaging 6.0.9、Local Notification 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',
);

}

最佳答案

我找到了解决方案,这就是为什么在平台端我们不注册外部插件

添加你的 FCMPluginRegistrant.java 像

public final  class FirebaseCloudMessagingPluginRegistrant {

public static void registerWith(PluginRegistry registry) {

if (alreadyRegisteredWith(registry)) {
return;
}
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
FlutterLocalNotificationsPlugin.registerWith(registry.registrarFor("com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"));


}




private static boolean alreadyRegisteredWith(PluginRegistry registry) {
final String key = FirebaseCloudMessagingPluginRegistrant.class.getCanonicalName();
if (registry.hasPlugin(key)) {
return true;
}
registry.registrarFor(key);
return false;
}
}

并在 Application.java 上调用它
  @Override
public void registerWith(PluginRegistry registry) {



FirebaseCloudMessagingPluginRegistrant.registerWith(registry);

}

关于firebase - MissingPluginException(在 channel dexterous.com/flutter/local_notifications 上找不到方法显示的实现),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60471697/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com