2

我正面临 Flutter2 和本地通知插件的问题。当应用程序处于前台时 - 本地通知工作完美,但当应用程序处于后台时 - 我收到 MissingPluginException 错误:

E/flutter (18894): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: MissingPluginException(No implementation found for method show on channel dexterous.com/flutter/local_notifications)
E/flutter (18894): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:7)
E/flutter (18894): <asynchronous suspension>
E/flutter (18894): #1      FlutterLocalNotificationsPlugin.show (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:179:7)
E/flutter (18894): <asynchronous suspension>

我的发布规范:

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  flutter_local_notifications: ^5.0.0+4

# firebase
  firebase_core: ^1.0.1
  firebase_auth: ^1.0.3
  cloud_firestore: ^1.0.4
  firebase_storage: ^8.0.3
  firebase_messaging: ^9.1.1
  firebase_core_platform_interface: ^4.0.0
  firebase_analytics: ^7.0.0
  firebase_dynamic_links: ^0.8.0
  firebase_crashlytics: ^2.0.3

还有我的 MainActivity 文件:

import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.os.PersistableBundle
import com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugins.FirebaseCloudMessagingPluginRegistrant
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService
import zendesk.core.Zendesk


class MainActivity : FlutterActivity() {

    override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
        super.onCreate(savedInstanceState, persistentState)
    }


    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channelName).setMethodCallHandler { call, result ->
            if (call.method == "start") {
                start(call, result)
            } else {
            }
        }
    }

}

我还在应用启动时发现了警告:

I/FLTFireBGExecutor(21072): Creating background FlutterEngine instance, with args: [--start-paused, --enable-dart-profiling]
W/FlutterEngine(21072): Tried to automatically register plugins with FlutterEngine (io.flutter.embedding.engine.FlutterEngine@b3b4ecc) but could not find and invoke the GeneratedPluginRegistrant.
4

0 回答 0