volume_regulator 2.2.0 copy "volume_regulator: ^2.2.0" to clipboard
volume_regulator: ^2.2.0 copied to clipboard

A Flutter plugin to monitor and adjust device volume from 0 to 100%.

example/lib/main.dart

/*
 *  main.dart
 *
 *  Created by Ilia Chirkunov <xc@yar.net> on 16.01.2021.
 */

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

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double _volume = 0;

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

    // Init slider.
    VolumeRegulator.getVolume().then((value) {
      setState(() {
        _volume = value.toDouble();
      });
    });

    // Listening to volume change events.
    VolumeRegulator.volumeStream.listen((value) {
      setState(() {
        _volume = value.toDouble();
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: const Text('Volume Regulator'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                'Volume: ${_volume.round()}%',
              ),
              Slider(
                value: _volume,
                min: 0,
                max: 100,
                divisions: 100,
                label: _volume.round().toString(),
                onChanged: (double value) {
                  VolumeRegulator.setVolume(value.toInt());
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
8
likes
130
pub points
86%
popularity

Publisher

verified publisheryar.net

A Flutter plugin to monitor and adjust device volume from 0 to 100%.

Repository (GitHub)
View/report issues

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on volume_regulator