未处理的异常:MissingPluginException(在通道 awesome_notifications 上找不到方法初始化的实现)

我已经在 main.dart 中初始化了 awesome_notifications 插件当我热启动时,在调试控制台中我收到了这个错误:

    E/flutter ( 4447): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel awesome_notifications)
E/flutter ( 4447): #0      MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:165
E/flutter ( 4447): <asynchronous suspension>
E/flutter ( 4447): #1      AwesomeNotifications.initialize (package:awesome_notifications/src/awesome_notifications_core.dart:174:18)
E/flutter ( 4447): <asynchronous suspension>
E/flutter ( 4447):
E/flutter ( 4447): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: MissingPluginException(No implementation found for method isNotificationAllowed on channel awesome_notifications)
E/flutter ( 4447): #0      MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:165
E/flutter ( 4447): <asynchronous suspension>

这是我的代码:

main.dart

Future<void> main() async {
  WidgetsFlutterBinding();
  await Hive.initFlutter();
  if (!Hive.isAdapterRegistered(AddEventModelAdapter().typeId)) {
    Hive.registerAdapter(AddEventModelAdapter());
  }
  AwesomeNotifications()
      .initialize('resource://drawable/res_notification_app_icon', [
    NotificationChannel(
      channelKey: 'schedule_channel',
      channelName: 'scheduled_channel',
      channelDescription: 'descroiption',
      locked: true,
      importance: NotificationImportance.High,
    ),
  ]);

  runApp(const MyApp());
}
stack overflow Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel awesome_notifications)
原文答案
author avatar

接受的答案

每当您在 pubspec.yaml 中添加插件时,您都需要停止应用程序并再次重新运行它,因为该插件在两个平台上都包含本机代码。

如果仍然无法正常工作,请执行 flutter clean 并运行。


答案:

相关问题