flutter - Flutter 后台服务
问题描述
嗨,我正在 Flutter 中构建一个 VoIP 应用程序。即使应用程序关闭,我也使用 background_fetch 运行无头任务以便工作。侦听器正在工作,并发送通知。但是,当应用程序关闭时,带有唤醒应用程序的推送通知(例如 home.dart),我想要推送我的呼叫屏幕小部件。我看到两个解决方案,但我不知道该怎么做:
- 来自 background_fetch 的无头任务是独立的,所以当用户打开它时我无法将我的服务调用数据传输到我的应用程序(主),所以调用丢失了......
- 我尝试推送正确的小部件(Router.go(/callscreen)),但它不起作用。
我该怎么做才能解决这个问题?感谢 !
解决方案
您在后台使用 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())
}
推荐阅读
- java-8 - 使用流 java 8 设置 id
- google-apps-script - 从亚马逊 MWS 订单中解析 XML
- python - ModelCluster ParentalManyToManyField 上的左外连接?
- python - Scrapy 错误:HTTP 状态代码未处理或不允许
- php - 可以在自己的定义中调用函数吗?
- javascript - dGrid 表格以编程方式水平滚动
- django - Django 正则表达式验证器消息未显示
- javascript - 无法在“CanvasRenderingContext2D”上执行“createPattern”:源图像处于“损坏”状态
- php - 致命错误:访问 SQL Server 表时
- c# - 系统无法在visual studio中执行指定程序