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

套件詳情v1.2.0

focusable_control_builder

輕鬆建立能正確回應滑鼠與鍵盤的自訂控制項。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1720
喜歡數
52
Pub 分數
140

安裝套件

flutter pub add focusable_control_builder

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,可簡化自訂 UI 控制項的建立,並正確處理鍵盤與滑鼠焦點。它提供建構器模式,以在各個平台一致地管理焦點狀態、可存取性與輸入事件。開發者可以輕鬆實作按鈕、滑桿或表單欄位等互動元件,這些元件能正確回應標籤導航、鍵盤捷徑與指標互動。此套件確保輔助技術與依賴非觸控輸入方式的使用者獲得無縫的使用者體驗。

適用情境

  • 建立可存取的表單輸入
  • 建構自訂互動式小部件
  • 在複雜 UI 中啟用鍵盤導航
  • 支援螢幕閱讀器和輔助技術
  • 在應用程式中實現選項卡導航
  • 為桌面和網路設計響應式控制項

主要特色

  • 內建焦點狀態管理
  • 鍵盤事件處理
  • 滑鼠指標整合
  • 跨平台一致性
  • 無障礙設計
  • 簡單的建構器 API

適合對象

  • 開發無障礙應用的開發者
  • 針對桌面與網路的 Flutter 項目
  • 重視鍵盤使用者體驗的團隊
  • 自定義 widget 建立者
  • 需要完整鍵盤導航的應用程式

使用建議

  • 需要理解焦點語意
  • 可能需要額外的樣式以提供視覺反饋
  • 最佳搭配語意化 UI 模式使用
  • 對於僅支援觸控的簡單介面來說並非必要
  • 與現有焦點樹的整合可能需要謹慎處理

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

focusable_control_builder

Using FocusableControlBuilder you can quickly create a new control that will work properly on all platforms and input devices.

Working "properly" entails support for:

  • tab key traversal
  • focus / rollover states
  • modified mouse cursor
  • support for keyboard shortcuts (Enter/Space by default)

Under the hood, this builder wraps the built in FocusableActionDetector and you can read there for more details about how it all works.

For more information on why you'd use these widgets, see this blog post: https://blog.gskinner.com/archives/2021/06/flutter-building-custom-components-with-focusableactiondetector.html

🔨 Installation

$ flutter pub add focusable_control_builder
⚙ Import
import 'package:focusable_control_builder/focusable_control_builder.dart';

🕹️ Usage

To create a custom button just implement the FocusableControlBuilder.builder method and assign an onPressed handler:

class MyCustomButton extends StatelessWidget {
  const MyCustomButton(this.label, {Key? key, required this.onPressed}) : super(key: key);
  final String label;
  final VoidCallback onPressed;
  @override
  Widget build(BuildContext context) {
    return FocusableControlBuilder(
        onPressed: onPressed,
        builder: (_, FocusableControlState control) {
          // Decide which colors to use, based on .isFocused and .isHovered
          Color outlineColor = control.isFocused ? Colors.black : Colors.transparent;
          Color bgColor = control.isHovered ? Colors.blue.shade100 : Colors.grey.shade200;
          // Return custom button contents
          return Container(
            padding: const EdgeInsets.all(8),
            child: Text(label),
            decoration: BoxDecoration(
              color: bgColor,
              border: Border.all(color: outlineColor, width: 1),
            ),
          );
        });
  }
}
Custom Mouse Cursor

FocusableControlBuilder will assume you want a "hand" cursor for your control, which is typically the case. If you'd like a different cursor, just assign it:

return FocusableControlBuilder(
    cursor: SystemMouseCursors.resizeDown,
    ...
);
Request Focus On Press

FocusableControlBuilder will assume you want your control to request focus when it is pressed. To disable, just set this to false:

return FocusableControlBuilder(
    requestFocusOnPress: false,
    ...
);
Custom Shortcuts

FocusableControlBuilder will create a default activation action which handles [Submit] and [Enter] keys. To create custom keyboard shortcuts you can set the .shortcuts and .actions parameters. This is a bit beyond the scope of this doc, but if you'd like to learn how, checkout the FocusableActionDetector docs which contain an example.

🐞 Bugs/Requests

If you encounter any problems please open an issue. If you feel the library is missing a feature, please raise a ticket on Github and we'll look into it. Pull request are welcome.

📃 License

MIT License

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。