I wanted to check if my app is in the background or foreground, Therefore the following method will give the state of the App.
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
switch (state) {
case AppLifecycleState.inactive:
print('appLifeCycleState inactive');
break;
case AppLifecycleState.resumed:
print('appLifeCycleState resumed');
break;
case AppLifecycleState.paused:
print('appLifeCycleState paused');
break;
case AppLifecycleState.detached:
print('appLifeCycleState detached');
break;
}
}
Scenario: I have one task that should perform on Resume/Pause all over the app. As I am having many different screens, It won't be good to implement them separately for every class.
Is there any way to create one common class and extend it to every widget?
Create one file called
base_state.dartand paste the following code.Now extend your StatefulWidget with
BaseStateinstead ofStatelike this.