パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v2.0.1

focus_detector

ウィジェットが画面に表示されたり、画面から消えたりするタイミングを検出します。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
3.7万
いいね数
362
Pub ポイント
130

パッケージをインストール

flutter pub add focus_detector

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

FocusDetector は、ウィジェットがフォーカスを獲得または失ったときに検出するためのFlutterパッケージであり、開発者が可視性の変化にリアルタイムで対応できるようにします。ウィジェットが画面に表示されたとき(フォーカス獲得)や非表示になったとき(フォーカス喪失)にコールバックを提供し、アニメーション、ユーザー操作の追跡、可視性に基づく状態管理に最適です。このパッケージはAndroid、iOS、Web、macOS、Windows、Linuxなどすべての主要プラットフォームで動作し、ターゲット環境に関係なく一貫した挙動を保証します。既存のFlutterアプリへの統合も最小限のセットアップでスムーズに行えます。

用途

  • 分析用のトラッキングウィジェットの可視性
  • 表示時にアニメーションをトリガーする
  • フォーカス状態に基づく状態の管理
  • 非アクティブなウィジェットを一時停止してパフォーマンスを最適化する
  • フォーカスの変更に反応するレスポンシブUIの実装

主な機能

  • リアルタイムフォーカス検出
  • クロスプラットフォーム互換性
  • シンプルなコールバックベースの API
  • 軽量で統合が簡単
  • フォーカス獲得および喪失イベントの両方をサポート

適している対象

  • インタラクティブUIを構築する開発者
  • 可視性を意識した論理を必要とするアプリ
  • ユーザーのフォーカスによってトリガーされるアニメーション
  • パフォーマンスに敏感なアプリケーション
  • ライフサイクルの意識が必要なウィジェット

注意事項

  • 適切なウィジェットツリー構造が必要です
  • 複雑なネストされたレイアウトでは、期待通りに動作しない可能性があります
  • インタラクティブでないウィジェットには適していません
  • フォーカス関連イベントに限定
  • 状態を持つウィジェットまたはコントローラーと併用するのが最適です

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Focus Detector Logo

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

Focus Detector

Get notified every time your widget appears or disappears from the screen.

Similar to onResume()/onPause() on Android and viewDidAppear()/viewDidDisappear() on iOS.

Focus Detector fires callbacks for you whenever something happens to take or give your widget focus. Such an event might be, for instance, the user:

  • Navigating to/from another screen;
  • Turning the device’s screen on/off while your widget is visible;
  • Switching to/from another app while your widget is visible;
  • Scrolling your widget in/out the screen;

Usage

@override
Widget build(BuildContext context) =>
    FocusDetector(
      onFocusLost: () {
        logger.i(
          'Focus Lost.'
          '\nTriggered when either [onVisibilityLost] or [onForegroundLost] '
          'is called.'
          '\nEquivalent to onPause() on Android or viewDidDisappear() on iOS.',
        );
      },
      onFocusGained: () {
        logger.i(
          'Focus Gained.'
          '\nTriggered when either [onVisibilityGained] or [onForegroundGained] '
          'is called.'
          '\nEquivalent to onResume() on Android or viewDidAppear() on iOS.',
        );
      },
      onVisibilityLost: () {
        logger.i(
          'Visibility Lost.'
          '\nIt means the widget is no longer visible within your app.',
        );
      },
      onVisibilityGained: () {
        logger.i(
          'Visibility Gained.'
          '\nIt means the widget is now visible within your app.',
        );
      },
      onForegroundLost: () {
        logger.i(
          'Foreground Lost.'
          '\nIt means, for example, that the user sent your app to the background by opening '
          'another app or turned off the device\'s screen while your '
          'widget was visible.',
        );
      },
      onForegroundGained: () {
        logger.i(
          'Foreground Gained.'
          '\nIt means, for example, that the user switched back to your app or turned the '
          'device\'s screen back on while your widget was visible.',
        );
      },
      child: Container(),
    );

Usage Scenarios

  • Turn on and off resource-consuming features, such as camera, location or bluetooth;
  • Sync your data with a remote API or local database;
  • Pause and resume video/audio playback or streaming;

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト