From 678b7911176fd70a15834e7fb523fc1c5420f177 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Tue, 25 Jun 2024 11:56:53 +0300 Subject: [PATCH] Fixed home page timer state when checking phone notifications on iOS --- .github/workflows/dart.yml | 2 +- lib/presentation/pages/home_page.dart | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 488814f..73c484c 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -9,7 +9,7 @@ on: env: flutter_channel: 'stable' # or: 'dev' or 'beta' - flutter_version: '3.22.0' + flutter_version: '3.22.2' jobs: build: diff --git a/lib/presentation/pages/home_page.dart b/lib/presentation/pages/home_page.dart index 5e61106..9f6ec73 100644 --- a/lib/presentation/pages/home_page.dart +++ b/lib/presentation/pages/home_page.dart @@ -36,14 +36,29 @@ class _HomePageState extends State with WidgetsBindingObserver { TimerStateManager.iterateOverTimerStates(); } + AppLifecycleState currentAppState = AppLifecycleState.resumed; + + void setAppState(AppLifecycleState val) { + if (val == AppLifecycleState.paused || val == AppLifecycleState.resumed) { + currentAppState = val; + } + } + @override Future didChangeAppLifecycleState(AppLifecycleState appState) async { switch (appState) { case AppLifecycleState.detached: case AppLifecycleState.inactive: case AppLifecycleState.hidden: + setAppState(appState); return; case AppLifecycleState.resumed: + if (currentAppState == AppLifecycleState.resumed) { + return; + } + + setAppState(appState); + NotificationsController.instance.cancelAllNotifications(); final DateTime preferencePausedTime = @@ -66,6 +81,8 @@ class _HomePageState extends State with WidgetsBindingObserver { ); return; case AppLifecycleState.paused: + setAppState(appState); + final bool isTimerRunning = TimerStateManager.isTimerRunning(); TimerStateManager.pauseTimer(); @@ -139,7 +156,7 @@ class _HomePageState extends State with WidgetsBindingObserver { body: PageView( onPageChanged: (index) { setState(() { - if (index == 0){ + if (index == 0) { FocusScope.of(context).unfocus(); } _currentTabNum = index;