Skip to content
pubscout

focus_detector

2.0.1, released 5 years ago by edsonbueno.com

Detects when your widget appears or disappears from the screen.

WASM-ready
$ flutter pub add focus_detector
Source repository

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.

Works with

Packages commonly used together with focus_detector: ones it builds on, ones built on it, and its own family.