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

问题描述 投票:0回答:1

我已经在 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());
}
flutter awesome-notifications
1个回答
28
投票

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

如果仍然不起作用,请执行

flutter clean
,然后执行
flutter run

© www.soinside.com 2019 - 2024. All rights reserved.