未处理的异常:MissingPluginException(在通道 plugins.flutter.io/firebase_messaging 上找不到方法 getToken 的实现)

Posted

技术标签:

【中文标题】未处理的异常:MissingPluginException(在通道 plugins.flutter.io/firebase_messaging 上找不到方法 getToken 的实现)【英文标题】:Unhandled Exception: MissingPluginException(No implementation found for method getToken on channel plugins.flutter.io/firebase_messaging) 【发布时间】:2020-05-29 05:30:26 【问题描述】:

我尝试为我的 Flutter 应用获取 Firebase 云消息传递令牌。在android模拟器上运行这里出了什么问题?我试过 flutter run 但这不起作用,我在这里使用 1.firebase_messaging: ^6.0.9 作为依赖项2.

    import 'package:flutter/material.dart';
import 'package:firebase_messaging/firebase_messaging.dart';

class Notifications_ extends StatefulWidget 
  @override
  _Notifications_State createState() => _Notifications_State();


class _Notifications_State extends State<Notifications_> 

  final FirebaseMessaging _messaging=FirebaseMessaging();

  @override
  void initState() 
    super.initState();

    _messaging.getToken().then((token)
    
      print(token);
    );

  

  @override
  Widget build(BuildContext context) 
    return Scaffold(
      appBar: AppBar(
        title: Text('notification'),
      ),
      body: Text('body testing'),
    );
  

 E/flutter ( 5931): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method getToken on channel plugins.flutter.io/firebase_messaging)

E/flutter (5931): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:319:7) E/颤动​​(5931): E/flutter (5931):#1 FirebaseMessaging.getToken (package:firebase_messaging/firebase_messaging.dart:150:27) E/颤振(5931):#2 _Notifications_State.initState(包:sampletestingpro/Notification.dart:17:16) E/flutter(5931):#3 StatefulElement._firstBuild(包:flutter/src/widgets/framework.dart:4355:58) E/flutter (5931):#4 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter(5931):#5 Element.inflateWidget(包:flutter/src/widgets/framework.dart:3194:14) E/flutter(5931):#6 Element.updateChild(包:flutter/src/widgets/framework.dart:2988:12) E/flutter (5931):#7 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter (5931):#8 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter (5931):#9 StatelessElement.update (package:flutter/src/widgets/framework.dart:4298:5) E/flutter (5931): #10 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15) E/flutter (5931): #11 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter (5931): #12 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter (5931): #13 StatelessElement.update (package:flutter/src/widgets/framework.dart:4298:5) E/flutter (5931): #14 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15) E/flutter (5931):#15 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter (5931): #16 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter (5931): #17 ProxyElement.update (package:flutter/src/widgets/framework.dart:4557:5) E/flutter(5931):#18 Element.updateChild(包:flutter/src/widgets/framework.dart:2977:15) E/flutter(5931):#19 ComponentElement.performRebuild(包:flutter/src/widgets/framework.dart:4243:16) E/flutter (5931): #20 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter (5931): #21 ProxyElement.update (package:flutter/src/widgets/framework.dart:4557:5) E/flutter (5931): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15) E/flutter (5931): #23 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5161:32) E/flutter (5931):#24 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5561:17) E/flutter (5931): #25 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15) E/flutter(5931):#26 ComponentElement.performRebuild(包:flutter/src/widgets/framework.dart:4243:16) E/flutter (5931): #27 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter (5931): #28 StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5) E/flutter (5931): #29 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15) E/flutter (5931):#30 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter(5931):#31 Element.rebuild(包:flutter/src/widgets/framework.dart:3947:5) E/flutter (5931):#32 ProxyElement.update (package:flutter/src/widgets/framework.dart:4557:5) E/flutter(5931):#33 Element.updateChild(包:flutter/src/widgets/framework.dart:2977:15) E/flutter (5931):#34 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter(5931):#35 Element.rebuild(包:flutter/src/widgets/framework.dart:3947:5) E/flutter (5931):#36 StatefulElement.update (package:flutter/src/widgets/framework.dart:4413:5) E/flutter(5931):#37 Element.updateChild(包:flutter/src/widgets/framework.dart:2977:15) E/flutter(5931):#38 SingleChildRenderObjectElement.update(包:flutter/src/widgets/framework.dart:5452:14) E/flutter(5931):#39 Element.updateChild(包:flutter/src/widgets/framework.dart:2977:15) E/flutter(5931):#40 ComponentElement.performRebuild(包:flutter/src/widgets/framework.dart:4243:16) E/flutter (5931): #41 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter (5931): #42 StatelessElement.update (package:flutter/src/widgets/framework.dart:4298:5) E/flutter(5931):#43 Element.updateChild(包:flutter/src/widgets/framework.dart:2977:15) E/flutter(5931):#44 SingleChildRenderObjectElement.update(包:flutter/src/widgets/framework.dart:5452:14) E/颤振(5931):#45 Element.update.

【问题讨论】:

插件不会通过热重载加载。您需要重新构建项目以使其正常工作。 【参考方案1】:

将 google JSON 服务文件保存在 app 文件夹中,我错误地将 JSON 文件放入 src/ 文件夹中,这就是我收到错误的原因

【讨论】:

我在 ios 设备上遇到了这个问题 对于 iOS:请确保您的 ios 项目中有 GoogleService-Info.plist 并执行 ios 文件夹的根目录 pod install pod update 然后 flutter run --verbose 我将我的 google JSON 服务文件放在 app 文件夹中。仍然遇到这个问题,您有什么想法吗?【参考方案2】:

所以在尝试了许多解决方案后,这对我有用!

MissingPluginException(No implementation found for method FcmDartService#initialized on channel plugins.flutter.io/firebase_messaging_background

【讨论】:

以上是关于未处理的异常:MissingPluginException(在通道 plugins.flutter.io/firebase_messaging 上找不到方法 getToken 的实现)的主要内容,如果未能解决你的问题,请参考以下文章

SQL 异常未处理 - System.Data.dll 中出现“System.Data.SqlClient.SqlException”类型的未处理异常

如何生成未处理的 MFC 异常?

Elasticsearch未分配分片异常处理

在 mvc 中处理请求时发生未处理的异常

捕获未处理的异常

如何在未处理的任务异常上崩溃?