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

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

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:hardware_buttons_find_flutter/hardware_buttons_find_flutter_method_channel.dart'
    as HardwareButtons;

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

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
0
pub points
76%
popularity

Publisher

verified publisheralakbarheydarov.com

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

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on hardware_buttons_find_flutter