focus_on_it
2.0.1, released 3 years ago by luanemanuel.com.br
Get notified when a Flutter widget is focused or unfocused and react to it.
What it does
Provides a widget wrapper that triggers callbacks when a view or app lifecycle state changes. It lets you detect focus, visibility, foreground/background states, and app lifecycle events.
AI-written summary of version 2.0.1, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to pause or resume videos or camera previews when a widget comes into view.
- You want to trigger data synchronization when a specific screen or widget is focused.
- You need to handle app lifecycle events at the widget level.
Skip it when
- You only need global app lifecycle observation without widget-level granularity.
- Your project uses a Flutter version below 3.13.0.
Strengths
- Offers 13 different events including focus, visibility, and app lifecycle changes.
- Successor to the unmaintained Focus Detector package with modern AppLifecycleListener support.
- Supports Android, iOS, Windows, macOS, and Linux.
Weaknesses
- Requires a minimum Dart SDK of 3.1.0 and Flutter 3.13.0+.
- Web testing requires setting a specific environment variable (--dart-define=TEST=true).
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
FocusOnIt(
onFocus: () {
logger.i('Focus Gained.');
},
onUnfocus: () {
logger.i('Focus Lost.');
},
child: const Placeholder(),
)Alternatives
Packages that do the same job and could replace focus_on_it.
- touchable_opacity
A widget that animates the opacity of its child on touch events, similar to React Native.
44Compare - dpad_container
Dpad container focus navigation support for Android TV.
39Compare
Works with
Packages commonly used together with focus_on_it: ones it builds on, ones built on it, and its own family.