본문 바로가기
Flutter

[Flutter] - 플러터 앱 라이프사이클 감지 didChangeAppLifecycleState을 사용해서 셋팅 앱에서 돌아온 후 알림을 다시 조회해보자!

by s_hoonee 2024. 7. 16.
반응형
with  WidgetsBindingObserver

믹싱을 통해 해당 클래스를 추가하고 didChangeAppLifecycleState를 사용해서 감지는 잘 되는데 해당 메소드에서 로직이 안돌아간다면 ? 

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    switch (state) {
      case AppLifecycleState.resumed:
        debugPrint("========= AppLifecycleState.resumed =========");
        ref.read(notificationPermissionProvider.notifier).checkPermission();
        break;
      case AppLifecycleState.inactive:
        break;
      case AppLifecycleState.paused:
        debugPrint("========= AppLifecycleState.paused =========");

        break;
      case AppLifecycleState.detached:
        debugPrint("========= AppLifecycleState.detached =========");
        break;
      default:
      // Handle any other states that might be added in the future
        break;
    }
    super.didChangeAppLifecycleState(state);
  }

initState() 메소드에 옵저버 인스턴스를 등록해주자. dispose로 메모리 해제는 잊지말고.

    WidgetsBinding.instance.addObserver(this);