首页 > 解决方案 > Flutter 后台服务

问题描述

嗨,我正在 Flutter 中构建一个 VoIP 应用程序。即使应用程序关闭,我也使用 background_fetch 运行无头任务以便工作。侦听器正在工作,并发送通知。但是,当应用程序关闭时,带有唤醒应用程序的推送通知(例如 home.dart),我想要推送我的呼叫屏幕小部件。我看到两个解决方案,但我不知道该怎么做:

我该怎么做才能解决这个问题?感谢 !

标签: flutterbackground-fetchflutter-local-notification

解决方案


您在后台使用 2 个服务,flutter-local-notification 和 background-fetch。太多了。您只能在后台使用 flutter-local-notification。看看这里

    final newRouteName = "callScreen";//Future onSelectNotification(String payload) async 
    bool isNewRouteSameAsCurrent = false;

    Navigator.popUntil(context, (route) {
      if (route.settings.name == newRouteName) {
        isNewRouteSameAsCurrent = true;
      }
      return true;
    });

    if (!isNewRouteSameAsCurrent) {
      Navigator.of(context).push(CallScreen())
      
    }

推荐阅读