focus_on_it 1.0.3 copy "focus_on_it: ^1.0.3" to clipboard
focus_on_it: ^1.0.3 copied to clipboard

Get notified when a widget is focused or unfocused and react to it.

Flutter Focus On It Package

Pub.dev Badge GitHub Build Badge Effective Dart Badge MIT License Badge Flutter Platform Badge

A continuation of the Focus Detector project which is not maintained anymore.

Get notified when a widget is focused or unfocused.


About #

Similar to onResume()/onPause() on Android and viewDidAppear()/viewDidDisappear() on iOS, Focus On It gives you the ability to know when a widget is focused or unfocused and let you do something about it.

Focus On It invoke callbacks when something happen to the widget focus. You can use it to get more control over your app and manage the events you might want, like:

  • Pause a video when the user is not looking at it.
  • Stop a camera preview when the user is not looking at it and start it again when the user is looking at it.
  • Turn off a resource intensive feature when the user is not looking at it and turn it on again when the user is looking at it.
  • Sync data with API when user open a screen.
  • And much more!

Events #

Focus On It offers 6 events to help you manage your app:

  • onFocus: Equivalent to onResume() on Android and viewDidAppear() on iOS. Triggered when the widget is focused after route transition or the widget resumed from a paused state.
  • onUnfocus: Equivalent to onPause() on Android and viewDidDisappear() on iOS. Triggered when the widget is unfocused after route transition or the widget paused from a focused state.
  • onForegroundGained: Triggered when the app is resumed from a paused state.
  • onForegroundLost: Triggered when the app is paused from a resumed state.
  • onVisibilityGained: Triggered when the widget is visible after route transition.
  • onVisibilityLost: Triggered when the widget is no longer visible after route transition.

Usage #

@override
Widget build(BuildContext context) =>
    FocusOnIt(
      onFocus: () {
        /// Equivalent to `onResume()` on Android and `viewDidAppear()` on iOS. 
        /// Triggered when the widget is focused after route transition or the widget resumed from a paused state.
        logger.i('Focus Gained.');
      },
      onUnfocus: () {
        /// Equivalent to `onPause()` on Android and `viewDidDisappear()` on iOS. 
        /// Triggered when the widget is unfocused after route transition or the widget paused from a focused state.
        logger.i('Focus Lost.');
      },
      onForegroundGained: () {
        /// Triggered when the app is resumed from a paused state.
        logger.i('Foreground Gained.');
      },
      onForegroundLost: () {
        /// Triggered when the app is paused from a resumed state.
        logger.i('Foreground Lost.');
      },
      onVisibilityGained: () {
        /// Triggered when the widget is visible after route transition.
        logger.i('Visibility Gained.');
      },
      onVisibilityLost: () {
        /// Triggered when the widget is no longer visible after route transition.
        logger.i('Visibility Lost.');
      },
      child: const Placeholder(),
    );

Example #

Maintainers #

33
likes
0
pub points
78%
popularity

Publisher

verified publisherluanemanuel.com.br

Get notified when a widget is focused or unfocused and react to it.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, visibility_detector

More

Packages that depend on focus_on_it