flutter_engine_state 0.0.5 copy "flutter_engine_state: ^0.0.5" to clipboard
flutter_engine_state: ^0.0.5 copied to clipboard

PlatformAndroid

A simple plugin to know whether the engine flutter is already detached or still attached

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

}

}

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>

0
likes
150
points
26
downloads

Publisher

unverified uploader

Weekly Downloads

A simple plugin to know whether the engine flutter is already detached or still attached

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_engine_state