Flutter:跨平台方式使应用程序在后台运行 [英] Flutter: cross-platform way to keep application running in the background

查看:834
本文介绍了Flutter:跨平台方式使应用程序在后台运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种方法,以确保Flutter应用程序即使不在焦点上也可以运行.例如,不管前台正在运行什么,都运行倒计时并在完成时播放警报声音/显示通知. 谁能指出我正确的方向?理想情况是跨平台的.

I'm trying to figure out a way to keep a Flutter application running even if it's not in focus. For instance have a countdown running and play an alarm sound/show notification on completion, no matter what's running in foreground. Can anyone point me in the right direction? Ideally something that works cross-platform.

我发现了这个

I found this thread but it's almost 2 years old, so I'm thinking maybe there has been some development since then.

推荐答案

这看起来像您可能想要的:

This looks like what you might want: https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124. It's a nice article on Medium describing how to run things in the background on both iOS and Android, especially using the most recent releases of Flutter.

Flutter在后台的官方文档位于 https://flutter.io/docs/development/packages-and-plugins/background-processes .关键是要在隔离中运行代码,因为在后台时您将无权访问GUI隔离.

The official documentation for Flutter in the background is at https://flutter.io/docs/development/packages-and-plugins/background-processes. The key is to run your code in an Isolate, because you won't have access to the GUI Isolate when you are in the background.

这篇关于Flutter:跨平台方式使应用程序在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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