搜索插件、代码仓与 APP 分类

插件详情v0.0.4

hardware_buttons_find_flutter

在具有不同按钮的移动设备上,监听按下按钮时的按钮名称。

Android
近 30 天下载
14
喜欢数
25
Pub 分数
135

安装插件

flutter pub add hardware_buttons_find_flutter

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,可让开发者检测并响应 Android 设备上的硬件按钮按下。它提供对特定按钮事件(如音量或电源按钮)的实时监听,使应用程序能够根据按下的按钮名称进行响应。非常适合根据物理输入自定义设备行为。该包轻量且可无缝集成到专注于 Android 的 Flutter 应用程序中。

适合场景

  • 自定义音量按钮按压处理
  • 检测电源按钮事件
  • 增强可访问性功能
  • 构建媒体控制应用
  • 创建基于手势的交互
  • 开发特定于应用程序的硬件快捷方式

主要特点

  • 实时按钮事件检测
  • 支持多个 Android 硬件按钮
  • 用于按钮名称识别的简单 API
  • 轻量且高效
  • 平台特定的 Android 实现
  • 轻松集成到Flutter应用

适合对象

  • 仅限 Android 的应用开发者
  • 需要硬件输入自定义的应用程序
  • 面向可访问性的应用程序
  • 媒体播放器或控制应用
  • 开发交互式设备体验的开发者

使用建议

  • 仅限 Android 平台
  • 需要 Android 特定权限
  • 可能不适用于所有设备型号
  • 无 iOS 支持
  • 行为可能因不同的 Android 版本而异
  • 不适用于通用按钮处理

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Hardware Buttons Find Flutter

  • [x] Android

Overview

It is necessary to learn the feedback of buttons on different types of reading devices and take steps based on it. This plugin will help you. This code, written with Stream, always listens to the native code, returning the name of the button to you when the button is pressed. Based on the answer you get, write down the functions you envision.


logo

How to use it

class _MyAppState extends State<MyApp> {
  String? _latestHardwareButtonEvent;

  StreamSubscription<String>? _buttonSubscription;

  @override
  void initState() {
    super.initState();
    _buttonSubscription = HardwareButtons.buttonEvents?.listen((event) {
      setState(() {
        _latestHardwareButtonEvent = event.toString();
      });
    });
  }

  @override
  void dispose() {
    super.dispose();
    _buttonSubscription?.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Hardware buttons find'),
        ),
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Text('Button name: $_latestHardwareButtonEvent\n'),
            ],
          ),
        ),
      ),
    );
  }
}

所属分类

依赖

依赖清单 1 项

  • plugin_platform_interface^2.0.2

源码仓库

使用此插件的项目

暂无相关数据。