hardware_buttons_find_flutter 0.0.4 copy "hardware_buttons_find_flutter: ^0.0.4" to clipboard
hardware_buttons_find_flutter: ^0.0.4 copied to clipboard

PlatformAndroid

On mobile devices with different buttons on it, listening for the name of the button when the buttons are pressed.

Hardware Buttons Find Flutter

  • ✅ 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'),
            ],
          ),
        ),
      ),
    );
  }
}
23
likes
140
points
95
downloads

Publisher

verified publisheralakbarheydarov.com

Weekly Downloads

On mobile devices with different buttons on it, listening for the name of the button when the buttons are pressed.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on hardware_buttons_find_flutter