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

套件詳情v1.0.0

hardware_buttons

一個適用於 iOS 和 Android 的 Flutter 插件,用於檢測各種硬體按鈕,例如音量鍵和主頁鍵。

近 30 天下載
50
喜歡數
49
Pub 分數
40

安裝套件

flutter pub add hardware_buttons

套件介紹

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

hardware_buttons 套件是 Flutter 插件,可檢測 iOS 與 Android 裝置上的實體硬體按鈕,包含音量加/減與主頁按鈕。它提供簡單的 API 來監聽按鈕按下的事件,讓開發者能夠回應應用內的硬體互動。這對於媒體控制、導航捷徑或自訂裝置特定行為特別有用。此套件支援兩個平台,並與 Flutter 的事件系統無縫整合。非常適合需要低階硬體輸入處理的應用程式。

適用情境

  • 媒體播放控制
  • 自定義導航手勢
  • 設備特定的應用行為
  • 可存取性增強
  • 遊戲控制器整合

主要特色

  • 即時按鈕事件偵測
  • 跨平台支援(iOS 與 Android)
  • 簡單的事件監聽器 API
  • 輕量且易於整合
  • 支援音量鍵與主頁鍵

適合對象

  • 需要硬體互動的移動應用
  • 媒體播放器應用
  • 注重可存取性的應用
  • 使用實體控制的遊戲
  • 需要設備特定邏輯的應用程式

使用建議

  • 僅限特定硬體按鈕
  • 不支援第三方硬體
  • 需要平台特定權限
  • 可能無法在所有裝置型號上運作
  • 事件處理依賴於作業系統層級的可用性

原始 README

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

DEPRECATED

This plugin is deprecated :( We're no longer able to maintain it.

hardware_buttons

Version GitHub license

A Flutter plugin for iOS and Android for detecting various hardware buttons.

Note: This plugin is still under development, and some APIs might not be available yet. Feedback and Pull Requests are most welcome!

Screenshots

screenshots

Features

  • Detect volume buttons
  • Detect home button
  • Detect lock(power) button
  • To be added...

Android specification

  • If you subscribe to volume button events, this plugin will inevitably request for ACTION_MANAGER_OVERLAY_PERMISSION, since we found out this was the only way to do it well in Flutter Plugin environment. We do show permission request window for you, so there's nothing you should do other than subscribing to the event channel. However, since users may be surprised why your app needs this permission, we suggest notifying users beforehand why this permission will be requested.
  • Migrated to AndroidX as of version 1.0.0. To use with original support libraries, use version 0.2.4. Note, however, pre-AndroidX will no longer be supported.

iOS specification

  • No VOLUME_DOWN events are emitted when the volume is already at its minimum. VOLUME_UP events vice versa. On the other hand, events always occur whenever user presses the button on Android.

Usage

Import the package

To use this plugin, follow the plugin installation instructions.

To use with AndroidX, install the latest version as above instructions. To use with original support libraries, install version 0.2.4 instead.

Use the plugin

Add the following import to your Dart code:

import 'package:hardware_buttons/hardware_buttons.dart';

In order to listen to volume button events, use volumeButtonEvents.listen as below:

StreamSubscription _volumeButtonSubscription;

@override
void initState() {
  super.initState();
  _volumeButtonSubscription = volumeButtonEvents.listen((VolumeButtonEvent event) {
    // do something
    // event is either VolumeButtonEvent.VOLUME_UP or VolumeButtonEvent.VOLUME_DOWN
  });
}

@override
void dispose() {
  super.dispose();
  // be sure to cancel on dispose
  _volumeButtonSubscription?.cancel();
}

Besides volume button events, there are also:

  1. Home button events, via homeButtonEvents.listen.
  2. Lock button events, via lockButtonEvents.listen.

Example

Find the example wiring in the example app.

API details

See the hardware_buttons.dart for more API details.

Issues and feedback

Please file issues to send feedback or report a bug. Thank you!

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。