搜尋套件、儲存庫與 APP 分類

套件詳情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 的開發者
  • 需要基於焦點的邏輯的應用程式
  • 互動式表單和輸入欄位
  • 需要焦點意識的遊戲或媒體播放器
  • 注重可訪問性的應用程式

使用建議

  • 在複雜的 widget 樹中可能需要小心處理
  • 不適合用於檢測一般螢幕方向的變更
  • 焦點狀態可能會因不同平台的行為而異
  • 僅限小部件級別的焦點,無法實現應用級別的可見性
  • 確保正確釋放以避免記憶體洩漏

原始 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 項

原始碼儲存庫

使用此套件的專案