Firebase 颤振不会使领航员

Firebase 颤振不会使领航员,firebase,flutter,dart,firebase-cloud-messaging,Firebase,Flutter,Dart,Firebase Cloud Messaging,我有一个Flatter应用程序,它接收来自Firebase云消息的通知,我正在尝试在应用程序中打开某个屏幕,根据通知日期,这是我的代码: FirebaseMessaging.onMessageOpenedApp.listen( (RemoteMessage message) { print("Data: ${message.data}"); if (message.data['title'] == 'dash') { print('Data t

我有一个Flatter应用程序,它接收来自Firebase云消息的通知,我正在尝试在应用程序中打开某个屏幕,根据通知日期,这是我的代码:

FirebaseMessaging.onMessageOpenedApp.listen(
  (RemoteMessage message) {
    print("Data: ${message.data}");
    if (message.data['title'] == 'dash') {
      print('Data title test: ${message.data['title']}');
        Navigator.pop(context);
        Navigator.of(context).push(
            PageRouteBuilder(pageBuilder: (BuildContext context, _, __) {
          return Dashboard();
        }));
        Navigator.pop(context);
    } else {
      print('else');
    }
  },
);
这是我在控制台上看到的错误:

I/flutter (x): Data: {title: dash, message: mensagem 123}
I/flutter (x): Data title test: dash
E/flutter (x): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).
E/flutter (x): Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.

我认为问题在于,您在按下仪表板后弹出了
Dashboard
页面

将相同的
BuildContext
传递给导航器。BuildContext表示挂载的小部件,在第一次调用时,您使用call
Navigator.of(context.pop
)处理它,但下一次调用
Navigator.of(context.push)。强制应用程序使用不再存在的无效上下文,因此出现此错误。