what is the best approach to managing app lifecycle state?
would you do it using a getxservice with WidgetsBindingObserver?
thanks in advance.
what is the best approach to managing app lifecycle state?
would you do it using a getxservice with WidgetsBindingObserver?
thanks in advance.
You can extend your controller class with FullLifeCycleController
instead of GetXController
.
FullLifeCycleController
actually extends GetXController with WidgetsBindingObserver.
This gist might help you out. :)
Extend your controller with FullLifeCycleController with FullLifeCycleMixin
.
class HomeController extends FullLifeCycleController with FullLifeCycleMixin {
@override
void onInit() {
//
super.onInit();
}
// Mandatory
@override
void onDetached() {
print('HomeController - onDetached called');
}
// Mandatory
@override
void onInactive() {
print('HomeController - onInative called');
}
// Mandatory
@override
void onPaused() {
print('HomeController - onPaused called');
}
// Mandatory
@override
void onResumed() {
print('HomeController - onResumed called');
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
log("App Resumed");
instantSubmit();
break;
case AppLifecycleState.inactive:
log("App InActive");
break;
case AppLifecycleState.paused:
log("App Paused");
break;
case AppLifecycleState.detached:
log("App Detached");
break;
case AppLifecycleState.hidden:
// TODO: Handle this case.
log("Hidden");
break;
}
}
}
© 2022 - 2024 — McMap. All rights reserved.