软件包更新后,Firebase Messaging软件包不起作用? [英] Firebase Messaging packages is not working after Package Update?

查看:84
本文介绍了软件包更新后,Firebase Messaging软件包不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    _firebaseMessaging.*configure*( onMessage: (Map<String, dynamic> message) async {
    print("\n\n on1Message: ${message.toString()}");
    Map<String, dynamic> object = json.decode(
        message['data']['notification'].toString());

    print(
        '\n\n Object==${message['data']}\n\n object===$object');
    object['work'] = 'updateCount';
    Stream<Map<String, dynamic>> stream =
        Stream.value(object);

    streamController.addStream(stream);

    print("\n\n object ---> ${object}");

控制台日志中的错误------------------------------------------------------------------722:24:错误:未为类"FirebaseMessaging"定义方法"configure".

Error in Console Log---------------------------------------------------------------- 722:24: Error: The method 'configure' isn't defined for the class 'FirebaseMessaging'.

  • 'FirebaseMessaging'来自'package:firebase_messaging/firebase_messaging.dart'('/E:/flutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging-9.1.0/lib/firebase_messaging.镖').尝试将名称更正为现有方法的名称,或定义一个名为"configure"的方法._firebaseMessaging.configure
    (^^^^^^^^^^

configure()方法不起作用.我尝试了与堆栈溢出不同的解决方案,但没有任何效果.我该怎么办.

configure() method is not working after the update of the Package of Firebase Cloud Messaging. I tried different solution from the stack overflow but nothing works. What Should I do in my case.

推荐答案

新的FirebaseMessaging有所不同.这是两个有趣的链接: https://firebase.google.com/docs/flutter/setup?platform=android https://firebase.flutter.dev/docs/messaging/usage/

The new FirebaseMessaging is a little bit different. Here are two interesting links: https://firebase.google.com/docs/flutter/setup?platform=android https://firebase.flutter.dev/docs/messaging/usage/

在将Firebase添加到App后,这就是我要做的(NotificationDetails是我编写的用于显示Notification详细信息的类.您可以编写自己的类.):

After adding firebase to the App, this is what I do (NotificationDetails is a class I wrote to show the details of the Notification. You can write you own class.):

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  runApp(
    MaterialApp(
      debugShowCheckedModeBanner: false,
      routes: {
      '/': (context) =>  AppStarter(),
      '/message': (context) => NotificationDetails(),
      },
     ),
    );
   }



class AppStarter extends StatefulWidget{
   @override
   _AppStarterState createState() => _AppStarterState();
  }



class _AppStarterState extends State<AppStarter>
   {

     FirebaseMessaging messaging = FirebaseMessaging.instance;

    Future<void> showMeMyToken()
    async {
      var myToken = await messaging.getToken();
      print("My Token is: " + myToken.toString());
    }


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

       showMeMyToken();

      FirebaseMessaging.instance.getInitialMessage().then((value) {
       if(value != null)
        {
          Navigator.push(context,
          MaterialPageRoute(
              builder: (context){return NotificationDetails();},
          settings: RouteSettings(arguments: value.data,),
         ),
        );
       }
     });


     FirebaseMessaging.onMessage.listen((RemoteMessage message) {


        if (message.notification != null) {
           print('Message on Foreground: ${message.notification}');
              }
         });


      FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message)
       {
         Navigator.push(
           context,
           MaterialPageRoute(
               builder: (context) {return NotificationDetails();},
               settings: RouteSettings(arguments: message.data,)
          ),
        );
     });

     FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
   }


   @override
    Widget build(BuildContext context) {

      return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Just a Test',
        
        home: AppHome(),
       );
      }
   }




   Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
     await Firebase.initializeApp();

      print("Handling a background message :-): ${message.data}");
      //Here you can do what you want with the message :-)
     }

这篇关于软件包更新后,Firebase Messaging软件包不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆