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

パッケージ詳細v3.1.0+1

focus_detector_v2

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

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
19
いいね数
51
Pub ポイント
160

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

flutter pub add focus_detector_v2

パッケージ概要

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

FocusDetectorV2 は、ウィジェットがフォーカスを獲得または喪失したときに検出する Flutter パッケージであり、それが画面に表示されるか否かを示します。リアルタイムで可視性およびフォーカス状態のフィードバックを提供し、ユーザー操作や画面内での存在に基づいて UI の振る舞いを管理するのに最適です。このパッケージは Android、iOS、Web、macOS、Windows、Linux など複数のプラットフォームをサポートしており、クロスプラットフォームの一貫性を確保しています。軽量で、既存の Flutter プロジェクトへの統合もスムーズです。

用途

  • リアルタイムでのウィジェットの可視性の追跡
  • フォーカス状態に基づいてアニメーションを管理する
  • 非アクティブなウィジェットを一時停止してパフォーマンスを最適化する
  • フォーカス対応のUIコンポーネントの実装
  • マルチスクリーンアプリにおける画面遷移の処理

主な機能

  • リアルタイムフォーカス検出
  • クロスプラットフォーム互換性
  • 既存のウィジェットとの簡単な統合
  • フォーカスの取得および喪失イベントの両方をサポートしています
  • 軽量かつ効率的

適している対象

  • レスポンシブ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.',
        );
      },
      isWidgetTest: false,
      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;

Migrating from 'focus_detector'

This is a forked version of Focus Detector. It was not updated for more than a year, so I made the V2 for my personal projects. To migrate from the V1, update the pubspec.yml dependency from focus_detector: ^2.0.1 to focus_detector_v2: ^3.1.0 and adjust your import inside dart files.

Contribution

Contributions of any kind are welcome. Feel free to improve the library by creating a pull request or opening an issue.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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