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

a flutter plugin to listen to volume button press events on android and ios.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:volume_listener/volume_listener.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  VolumeKey? lastKey;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    VolumeListener.addListener((VolumeKey event) {
      setState(() {
        lastKey = event;
      });
    });
  }

  @override
  void dispose() {
    VolumeListener.removeListener();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Last key:  $lastKey\n'),
        ),
      ),
    );
  }
}
9
likes
160
points
534
downloads

Publisher

verified publisherfolksable.com

Weekly Downloads

a flutter plugin to listen to volume button press events on android and ios.

Repository (GitHub)
View/report issues

Topics

#volume #audio

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on volume_listener