This plugin is deprecated :( We're no longer able to maintain it.
hardware_buttons
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
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.
In order to listen to volume button events, use volumeButtonEvents.listen as below:
StreamSubscription _volumeButtonSubscription;
@overridevoidinitState() {
super.initState();
_volumeButtonSubscription = volumeButtonEvents.listen((VolumeButtonEvent event) {
// do something// event is either VolumeButtonEvent.VOLUME_UP or VolumeButtonEvent.VOLUME_DOWN
});
}
@overridevoiddispose() {
super.dispose();
// be sure to cancel on dispose
_volumeButtonSubscription?.cancel();
}