visibility_aware_state
1.0.5, released 4 years ago by ehwplus.com
A State for StatefulWidgets that provides visibility awareness similar to Android activity lifecycles.
What it does
Provides a VisibilityAwareState class for StatefulWidgets that detects when widgets become visible, invisible, pushed, popped, or when the app enters the background. It allows developers to override onVisibilityChanged to handle these lifecycle events and check current visibility.
AI-written summary of version 1.0.5, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need screen view tracking when widgets become visible.
- You need to automatically refresh data when a user returns to a screen.
- You want Android-like onResume lifecycle callbacks for Flutter widgets.
Skip it when
- You are managing complex global application state across multiple independent features.
- You prefer reactive stream-based architecture over stateful mixins.
Strengths
- Simple API similar to Android activity lifecycle methods.
- Tracks whether the app is in the background or foreground automatically.
- Provides helper methods like finish() and isVisible().
Weaknesses
- Limited to managing widget visibility state rather than general app state management.
- Relies on extending a specific custom State class rather than composition or hooks.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
Not documented
class _ExampleState extends VisibilityAwareState<Example> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Example app')),
body: Center(child: Text('Welcome.')),
);
}
@override
void onVisibilityChanged(WidgetVisibility visibility) {
super.onVisibilityChanged(visibility);
}
}Alternatives
Packages that do the same job and could replace visibility_aware_state.
- flutter_keyboard_visibility
Flutter plugin to detect soft keyboard visibility on Android, iOS, web, and desktop.
88Compare - 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 - stream_mixin
StreamMixin provides a lightweight stream‑based state manager for Flutter widgets.
46Compare