-
Notifications
You must be signed in to change notification settings - Fork 25
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
12 changed files
with
164 additions
and
138 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
lib/ui/views/main/components/home_providers_keepalive.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,59 @@ | ||
import 'package:aewallet/ui/views/main/bloc/providers.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
/// Eagerly initializes providers (https://riverpod.dev/docs/essentials/eager_initialization). | ||
/// | ||
/// Add Watch here for any provider you want to init when app is displayed. | ||
/// Those providers will be kept alive during application lifetime. | ||
class HomeProvidersKeepalive extends ConsumerStatefulWidget { | ||
const HomeProvidersKeepalive({required this.child, super.key}); | ||
|
||
final Widget child; | ||
|
||
@override | ||
ConsumerState<ConsumerStatefulWidget> createState() => | ||
_LoggedInProvidersState(); | ||
} | ||
|
||
class _LoggedInProvidersState extends ConsumerState<HomeProvidersKeepalive> | ||
with WidgetsBindingObserver { | ||
@override | ||
void initState() { | ||
super.initState(); | ||
WidgetsBinding.instance.addObserver(this); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
WidgetsBinding.instance.removeObserver(this); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
void didChangeAppLifecycleState(AppLifecycleState state) { | ||
didChangeAppLifecycleStateAsync(state); | ||
} | ||
|
||
Future<void> didChangeAppLifecycleStateAsync(AppLifecycleState state) async { | ||
switch (state) { | ||
case AppLifecycleState.paused: | ||
await ref.read(homePageProvider.notifier).stopSubscriptions(); | ||
break; | ||
case AppLifecycleState.resumed: | ||
await ref.read(homePageProvider.notifier).startSubscriptions(); | ||
break; | ||
case AppLifecycleState.inactive: | ||
case AppLifecycleState.detached: | ||
case AppLifecycleState.hidden: | ||
break; | ||
} | ||
super.didChangeAppLifecycleState(state); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
ref.watch(homePageProvider); | ||
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
Oops, something went wrong.