簡體   English   中英

Flutter 當應用程序從觸發的 Intent 進入前台時捕獲事件

[英]Flutter Capture event when app comes to Foreground from triggered Intent

我試圖在這里完成一些基本的東西。 場景:我正在使用isLocationServiceEnabled檢查init()上的 GPS 狀態。 如果 GPS 關閉,我將顯示一個使用AndroidIntent重定向到位置設置的彈出窗口。 如果在不打開 GPS 的情況下進行回擊,我想在我的應用程序進入前台時捕獲該事件。 我猜它與生命周期有關,並嘗試如下,控制台上沒有打印任何內容

    AppLifecycleState _notification;

    @override
    void didChangeAppLifecycleState(AppLifecycleState state) {
      setState(() {
        _notification = state;
        print('onResumed called 1');
        print(_notification);
      });
      if( state == AppLifecycleState.resumed){
        print('onResumed called 2');
      }
    }

我在這里錯過了什么嗎?

您是否像這樣使用WidgetsBindingObserver擴展 class :

class _WhateverWidget extends State<WhateverWidget> with WidgetsBindingObserver

然后像這樣初始化一個實例:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM