📜  在 Flutter 应用中允许后台服务 - Dart 代码示例

📅  最后修改于: 2022-03-11 14:48:05.202000             🧑  作者: Mango

代码示例1
class _MyHomePageState extends State with WidgetsBindingObserver {
  AppLifecycleState _notification; 
  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    setState(() {
      _notification = state;
    });
  }

  @override
  initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
    ...
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }
}