-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
576 additions
and
446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
coffee_maker_navigator_2/lib/app/app_lifecycle/domain/app_lifecyle_service.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:flutter/foundation.dart'; | ||
|
||
enum AppLifeCycleState { | ||
foreground, | ||
background, | ||
} | ||
|
||
class AppLifeCycleService { | ||
late ValueNotifier<AppLifeCycleState> lifeCycleState; | ||
|
||
ValueListenable<AppLifeCycleState> get appLifeStateListenable => | ||
lifeCycleState; | ||
|
||
AppLifeCycleService() { | ||
lifeCycleState = ValueNotifier(AppLifeCycleState.foreground); | ||
} | ||
|
||
void onForegrounded() { | ||
lifeCycleState.value = AppLifeCycleState.foreground; | ||
} | ||
|
||
void onBackgrounded() { | ||
lifeCycleState.value = AppLifeCycleState.background; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
coffee_maker_navigator_2/lib/app/app_lifecycle/ui/app_lifecycle_listenable.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'package:coffee_maker_navigator_2/app/di/coffee_maker_app_level_dependency_container.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:wolt_di/wolt_di.dart'; | ||
|
||
class AppLifecycleObserver extends StatefulWidget { | ||
const AppLifecycleObserver({required this.child, super.key}); | ||
|
||
final Widget child; | ||
|
||
@override | ||
State<AppLifecycleObserver> createState() => _AppLifecycleObserverState(); | ||
} | ||
|
||
class _AppLifecycleObserverState extends State<AppLifecycleObserver> { | ||
late final AppLifecycleListener listener; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
final appLevelDependencyContainer = | ||
DependencyInjector.container<CoffeeMakerAppLevelDependencyContainer>( | ||
context); | ||
final appLifeCycleService = appLevelDependencyContainer.appLifeCycleService; | ||
listener = AppLifecycleListener( | ||
onShow: () { | ||
debugPrint('AppLifecycleListener: onForegrounded'); | ||
appLifeCycleService.onForegrounded(); | ||
}, | ||
onHide: () { | ||
debugPrint('AppLifecycleListener: onBackgrounded'); | ||
appLifeCycleService.onBackgrounded(); | ||
}, | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
listener.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return widget.child; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.