focus_detector
2.0.1, released 5 years ago by edsonbueno.com
Detects when your widget appears or disappears from the screen.
What it does
FocusDetector provides callbacks to get notified every time a widget appears or disappears from the screen. It behaves similarly to onResume/onPause on Android or viewDidAppear/viewDidDisappear on iOS. It can trigger events when navigating, scrolling the widget in or out of view, or turning the device screen on and off.
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 turn on and off resource-consuming features like camera, location, or bluetooth based on widget visibility.
- You need to sync data with a remote API or local database when a screen gains focus.
- You need to pause and resume video or audio playback when navigating away from a screen.
Skip it when
- You only need basic page route transitions without sub-widget visibility detection.
Strengths
- Simple widget-based integration.
- Handles both visibility changes and app foreground/background transitions.
- Cross-platform support.
Weaknesses
- Relies on visibility_detector under the hood, which inherits its performance characteristics.
Setup
- Kind
- Flutter widgets
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
FocusDetector(
onFocusLost: () {
logger.i('Focus Lost.');
},
onFocusGained: () {
logger.i('Focus Gained.');
},
child: Container(),
)Alternatives
Packages that do the same job and could replace focus_detector.
- popover
Displays a transient iOS-style popover view above other content pointing at a control.
89Compare - inview_notifier_list
Builds a ListView or CustomScrollView and notifies when widgets are on screen.
67Compare - loader_overlay
Show a loading overlay to prevent user interaction during async operations.
66Compare - touch_indicator
Show touch indicators on the screen for screencasts and app demos.
50Compare
Works with
Packages commonly used together with focus_detector: ones it builds on, ones built on it, and its own family.