Last updated:
0 purchases
flutter engine state
flutter_engine_state_example #
This package is created due to the incapability of WidgetBindingObserver to know whether the flutter activity is detached or still attached. AppLifecycleState.detached did only work when SystemNavigator.pop() called but didn't work when user swipe a flutter app to clear.
Getting Started #
This package could resolve your problem when you want to know whether the activity of your app is attached or not. By knowing the state, you can do your specific task that should be runned in terminated state or not.
@pragma('vm:entry-point')
Future<void> handleBackgroundGoogleMessage(
RemoteMessage message,
) async {
debugPrint('\n==========BACKGROUND==========\n');
var sp = await SharedPreferences.getInstance();
await sp.reload();
var state = sp.getInt("flutterEngineState");
print(state);
if(state == 1){
// flutter engine is attached and activity is attached
// do something
} else {
// flutter engine is attached but the activity is detached
// do something
}
}
copied to clipboard
You should use flutterEngineState this key to get activity app state status.
Also we need to put service in AndroidManifest.xml to call SharedPreferences when user clear with swiping or clear all recent apps button
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application>
<activity
....
</activity>
...
<service android:name="com.zralogy.flutter_engine_state.AppClearService" android:stopWithTask="false"/>
...
</application>
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.