微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MissingPluginException在通道 dexterous.com/flutter/local_notifications 上找不到方法初始化的实现

如何解决MissingPluginException在通道 dexterous.com/flutter/local_notifications 上找不到方法初始化的实现

我正在尝试设置最基本版本的 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)

查看我自动生成插件注册人 java 文件

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 举报,一经查实,本站将立刻删除。