FLUTTER ECOSYSTEM

AlakbarHeyderov/hardware_buttons_find_flutter

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

hardware_buttons_find_flutter 项目封面
Stars
11
Forks
1
最近推送(UTC)
2023年1月17日
项目状态
未归档
Alakbar GitHub avatar
GITHUB User

Alakbar ↗

MenzilPark LLCAzerbaijan Baku
语言DartJava

此仓库发布的插件

使用的依赖

依赖清单 4 项
  • flutter{"sdk":"flutter"}
  • plugin_platform_interface^2.0.2
  • flutter_test开发依赖{"sdk":"flutter"}
  • flutter_lints开发依赖^2.0.0

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

展开 / 收起项目 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'),
            ],
          ),
        ),
      ),
    );
  }
}