control_volume 0.0.2 copy "control_volume: ^0.0.2" to clipboard
control_volume: ^0.0.2 copied to clipboard

PlatformAndroid

A Flutter volume plugin for android control system volume.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:control_volume/control_volume.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  double _volumeListenerValue = 0;
  double _getVolume = 0;
  double _getIncreaseRatioVolume = 0;
  double _setVolumeValue = 0;

  @override
  void initState() {
    super.initState();
    ControlVolume().listener((volume) {
      setState(() => _volumeListenerValue = volume);
    });
    ControlVolume().getVolume().then((volume) => _setVolumeValue = 0);
    print(_setVolumeValue);
  }

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


  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: [
            Text('Current volume: $_volumeListenerValue'),
            Row(
              children: [
                Text('Set Volume:'),
                Flexible(
                  child: Slider(
                    min: 0,
                    max: 1,
                    onChanged: (double value) {
                      setState(() {
                        _setVolumeValue = value;
                        ControlVolume().setVolume(_setVolumeValue);
                      });
                    },
                    value: _setVolumeValue,
                  ),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('Volume is: $_getVolume'),
                TextButton(
                  onPressed: () async {
                    _getVolume = await ControlVolume().getVolume();

                    setState(() {});
                  },
                  child: Text('Get Volume'),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('Increase Ratio Volume is: $_getIncreaseRatioVolume'),
                TextButton(
                  onPressed: () async {
                    _getIncreaseRatioVolume = await ControlVolume().getIncreaseRatioVolume();
                    setState(() {});
                  },
                  child: Text('Get Increase Ratio Volume'),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('Show system UI:${ControlVolume().showSystemUI}'),
                TextButton(
                  onPressed: () => setState(() => ControlVolume()
                      .showSystemUI = !ControlVolume().showSystemUI),
                  child: Text('Show/Hide UI'),
                )
              ],
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
110
pub points
25%
popularity

Publisher

unverified uploader

A Flutter volume plugin for android control system volume.

Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (LICENSE)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on control_volume