Search packages, repositories and app categories

Package detailsv1.0.0

hardware_buttons

A Flutter plugin for iOS and Android for detecting various hardware buttons such as volume and home button.

30-day downloads
50
Likes
49
Pub points
40

Install package

flutter pub add hardware_buttons

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The hardware_buttons package is a Flutter plugin that enables detection of physical hardware buttons on iOS and Android devices, including volume up/down and home buttons. It provides a simple API to listen for button press events, allowing developers to respond to hardware interactions within their apps. This is particularly useful for media controls, navigation shortcuts, or custom device-specific behaviors. The plugin supports both platforms and integrates seamlessly with Flutter's event system. It is ideal for applications requiring low-level hardware input handling.

Use cases

  • Media playback control
  • Custom navigation gestures
  • Device-specific app behavior
  • Accessibility enhancements
  • Game controller integration

Key features

  • Real-time button event detection
  • Cross-platform support (iOS & Android)
  • Simple event listener API
  • Lightweight and easy to integrate
  • Supports volume and home buttons

Suitable for

  • Mobile apps needing hardware interaction
  • Media player applications
  • Accessibility-focused apps
  • Games using physical controls
  • Apps requiring device-specific logic

Considerations

  • Limited to specific hardware buttons
  • No support for third-party hardware
  • Requires platform-specific permissions
  • May not work on all device models
  • Event handling depends on OS-level availability

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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!

Categories

Source repository

Projects using this package

No data available yet.