Skip to content
pubscout

volume_listener

0.1.0, released 2 years ago by folksable.com

A Flutter plugin to listen to volume button press events on Android and iOS.

WASM-ready
$ flutter pub add volume_listener
Source repository

What it does

It allows Flutter apps to listen for volume button press events (up, down, and capture) on both Android and iOS platforms. Developers can register a listener callback to handle these hardware button events and remove it when no longer needed.

AI-written summary of version 0.1.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to detect physical volume button presses in your app
  • You want to handle hardware camera capture button events on iOS 17.2+

Skip it when

  • You only need to play or record audio
  • You need complex media session management

Strengths

  • Cross-platform support for Android and iOS
  • Simple API with straightforward add and remove listener methods

Weaknesses

  • Requires manual modification of the Android MainActivity class
  • Limited to volume and capture button events

Setup

Kind
Plugin (native code)
Effort
Medium
Code generation
No
Direct dependencies
1

On Android, you must extend your MainActivity with VolumeListenerActivity and remove FlutterActivity.

VolumeListener.addListener((VolumeKey event) {
    switch (event) {
        case VolumeKey.up:
            print('Volume Up'); break;
        case VolumeKey.down:
            print('Volume Down'); break;
        case VolumeKey.capture:
            print('iOS Hardware Camera Capture'); 
            break;
    }
});
VolumeListener.removeListener();

Alternatives

Packages that do the same job and could replace volume_listener.

Works with

Packages commonly used together with volume_listener: ones it builds on, ones built on it, and its own family.