问题描述
我正在尝试找到一种方法,以确保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.
我发现了这个,但是它已经使用了将近2年,所以我想从那以后可能会有一些发展.
I found this thread but it's almost 2 years old, so I'm thinking maybe there has been some development since then.
推荐答案
这看起来像您可能想要的: https://medium.com/flutter-io/executing-dart-in-the-background-with-flutter-plugins-and -geofencing-2b3e40a1a124 .这是一篇有关Medium的不错的文章,描述了如何在iOS和Android上后台运行事物,尤其是使用最新版本的Flutter.
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:跨平台方式使应用程序在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!