flutterlifecyclehooks
5.0.0, released 2 years ago by ptsakoulis.com
Easily add application lifecycle state hooks using mixins or widgets.
What it does
Provides a LifecycleMixin and LifecycleHooksSubscriber widget that wrap AppLifecycleListener to handle application lifecycle states like resume, pause, show, and hide. It also offers an onContextReady callback where the BuildContext is available.
AI-written summary of version 5.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to easily listen to application lifecycle events inside a State object.
- You want a widget-based alternative to listen to lifecycle states without polluting widget namespaces.
Skip it when
- You are not using Flutter.
- You require complex state management solutions that handle business logic beyond just lifecycle observation.
Strengths
- Simplifies working with AppLifecycleListener via mixins and widgets.
- Provides an onContextReady method as a replacement for afterFirstRender.
- Cross-platform support including Android, iOS, Web, Windows, macOS, and Linux.
Weaknesses
- Limited to handling lifecycle hooks and context readiness.
- Web support for certain hooks was only added recently.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
Not documented
class _AppState extends State<App> with LifecycleMixin {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Text(
currentLifecycleState.toString(),
),
),
),
);
}
@override
void onResume() {
print('did resume');
}
}Alternatives
Packages that do the same job and could replace flutterlifecyclehooks.
- flutter_hooks
A Flutter implementation of React hooks for managing widget life-cycle and code reuse.
94Compare - yx_state
A state management library for Dart and Flutter applications.
82Compare - cached_query
Library for caching, background fetching, and managing server state in Dart and Flutter.
90Compare - replay_bloc
Adds automatic undo and redo support to bloc and cubit states.
80Compare