simple_lifecycle 0.0.1
simple_lifecycle: ^0.0.1 copied to clipboard
Binary lifecycle management for flutter.
simple_lifecycle #
The simple_lifecycle package provides a simple and intuitive way to manage the state of your Flutter application. It allows you to categorize the app's lifecycle events into two distinct states: active and paused.
The philosophy is that users are in two binary states, either active or inactive. We use the phrasing Paused instead of inactive for distinguishing.
Features #
Categorizes app events into active and paused states.
Handles events when the app is opened for the first time or comes from the background to the foreground.
Handles events when the app is closed, not in the foreground, or transitioning between different states.
Provides easy-to-use callbacks to perform actions based on the app's activity state.
Getting started #
TODO: List prerequisites and provide or point to information on how to start using the package.
Usage #
- Import the necessary packages:
import 'package:simple_lifecycle/simple_lifecycle.dart'; - Create an instance of SimpleLifecycle and initialize it:
final simpleLifecycle = SimpleLifecycle(); - Set the desired callbacks by assigning functions to the corresponding properties:
void initState() { simpleLifecycle.initialize(); super.initState(); simpleLifecycle.onAppActive = () { // Handle app active event }; simpleLifecycle.onAppPaused = () { // Handle app not active event }; } - Clean up the SimpleLifecycle when it's no longer needed to avoid memory leaks:
The SimpleLifecycle class provides four optional callback properties that allow you to handle specific app lifecycle events:@override void dispose() { super.dispose(); simplelifeCycle.dispose(); }
onAppActive: Invoked when the app is opened for the first time or restored from the background.onAppPaused: Invoked in any other case e.g. closed, background. You can assign custom functions to these properties to perform actions based on the corresponding app lifecycle events.
Remember to call the initialize method to start listening for app lifecycle changes and dispose when you're done to clean up resources.
Feel free to customize the implementation according to your specific needs and handle the lifecycle events accordingly.
Additional information #
🥤