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

Unhandled Exception: MissingPluginException(No implementation found for method getToken on channel plugins.flutter.io/firebase_messaging)

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
    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'),
    );
  }
}
1
 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/flutter ( 5931):
E/flutter ( 5931): #1 FirebaseMessaging.getToken (package:firebase_messaging/firebase_messaging.dart:150:27)
E/flutter ( 5931): #2 _Notifications_State.initState (package:sampletestingpro/Notification.dart:17:16)
E/flutter ( 5931): #3 StatefulElement._firstBuild (package: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 (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 5931): #6 Element.updateChild (package: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 (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter ( 5931): #19 ComponentElement.performRebuild (package: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 (package: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 (package: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 (package: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 (package: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 (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter ( 5931): #38 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
E/flutter ( 5931): #39 Element.updateChild (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter ( 5931): #40 ComponentElement.performRebuild (package: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 (package:flutter/src/widgets/framework.dart:2977:15)
E/flutter ( 5931): #44 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5452:14)
E/flutter ( 5931): #45 Element.update.


**Keep

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


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

MissingPluginException(在通道 plugins.flutter.io/firebase_messaging_background

上找不到方法 FcmDartService#initialized 的实现