问题描述
我正在尝试设置最基本版本的 Flutter 本地通知,但我不断收到此错误
[ERROR:Flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel dexterous.com/Flutter/local_notifications)
package io.Flutter.plugins;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
import io.Flutter.embedding.engine.FlutterEngine;
/**
* Generated file. Do not edit.
* This file is generated by the Flutter tool based on the
* plugins that support the Android platform.
*/
@Keep
public final class GeneratedpluginRegistrant {
public static void registerWith(@NonNull FlutterEngine FlutterEngine) {
FlutterEngine.getPlugins().add(new io.Flutter.plugins.firebase.firestore.FlutterFirebaseFirestorePlugin());
FlutterEngine.getPlugins().add(new io.Flutter.plugins.firebase.auth.FlutterFirebaseAuthPlugin());
FlutterEngine.getPlugins().add(new io.Flutter.plugins.firebase.core.FlutterFirebaseCorePlugin());
FlutterEngine.getPlugins().add(new io.Flutter.plugins.firebasedynamiclinks.FirebaseDynamicLinksPlugin());
FlutterEngine.getPlugins().add(new io.Flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin());
FlutterEngine.getPlugins().add(new io.Flutter.plugins.firebase.storage.FlutterFirebaseStoragePlugin());
FlutterEngine.getPlugins().add(new com.byneapp.Flutter_config.FlutterConfigPlugin());
FlutterEngine.getPlugins().add(new app.meedu.Flutter_facebook_auth.FlutterFacebookAuthPlugin());
FlutterEngine.getPlugins().add(new com.dexterous.Flutterlocalnotifications.FlutterlocalnotificationsPlugin());
FlutterEngine.getPlugins().add(new io.Flutter.plugins.googlesignin.GoogleSignInPlugin());
}
}
我发现该插件似乎已注册。那么为什么它会抛出错误。这是我使用的代码
import 'package:Flutter_local_notifications/Flutter_local_notifications.dart';
class FirebaseMessagingProvider extends PushNotificationProvider {
final FlutterlocalnotificationsPlugin FlutterlocalnotificationsPlugin = FlutterlocalnotificationsPlugin();
FirebaseMessagingProvider() {
initializelocalnotifications();
}
Future<void> initializelocalnotifications() async {
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('app_icon');
const AndroidNotificationChannel channel = AndroidNotificationChannel(
'high_importance_channel',// id
'High Importance Notifications',// title
'This channel is used for important notifications.',// description
importance: Importance.max,);
final InitializationSettings initializationSettings =
InitializationSettings(android: initializationSettingsAndroid);
await FlutterlocalnotificationsPlugin.initialize(initializationSettings,onSelectNotification: (_) async => print("notified"));
await FlutterlocalnotificationsPlugin
.resolvePlatformSpecificImplementation<AndroidFlutterlocalnotificationsPlugin>()
?.createNotificationChannel(channel);
}
}
await FlutterlocalnotificationsPlugin.initialize(initializationSettings,onSelectNotification: (_) async => print("notified"));
我看了下面的github问题
https://github.com/MaikuB/flutter_local_notifications/issues/238
但它似乎主要针对 Flutter 1 项目,您必须自己注册插件。我确实尝试过 application.kt,但没有奏效。
那为什么会出现这个错误?
Flutter 版本:Flutter 2.2.0 • 通道稳定 • https://github.com/flutter/flutter.git Flutter_local_notifications: ^6.0.0
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)