Firebase Messaging 包在包更新后不起作用?

Firebase Messaging packages is not working after Package Update?

    _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:错误:未为 class 'FirebaseMessaging'.

定义方法 'configure'

configure() 方法在 Firebase 云消息包更新后不起作用。我尝试了与堆栈溢出不同的解决方案,但没有任何效果。 我的情况应该怎么办。

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

在App中加入firebase之后,我就是这样做的(NotificationDetails是我写的class用来显示Notification的详细信息,你可以自己写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 :-)
     }