volume_watcher 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 78

volume_watcher #

支持ios 与 android 以下功能:
  1.实时监听返回系统音量值的改变,并返回音量值。 
  2.返回系统支持的最大音量,防止android不同机型最大值不同。 
  3.返回系统改变音量前的初始值。
  4.支持设置媒体音量
  
对外提供如下方法:
getMaxVolume
getCurrentVolume
setVolume(0.0)

对外提供监听:
onVolumeChangeListener

使用示例:
import 'package:flutter/material.dart';
import 'package:volume_watcher/volume_watcher.dart';

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> {
  num currentVolume = 0;
  num initVolume = 0;
  num maxVolume = 0;

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

  Future<void> initPlatformState() async {
    num initVolume = await VolumeWatcher.getCurrentVolume;
    num maxVolume = await VolumeWatcher.getMaxVolume;

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      this.initVolume = initVolume;
      this.maxVolume = maxVolume;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              VolumeWatcher(
                onVolumeChangeListener: (num volume) {
                  setState(() {
                    currentVolume = volume;
                  });
                },
              ),
              Text("最大音量=${maxVolume}"),
              Text("初始音量=${initVolume}"),
              Text("当前音量=${currentVolume}"),
              RaisedButton(
                onPressed: (){
                  VolumeWatcher.setVolume(maxVolume*0.5);
                },
                child: Text("设置音量为${maxVolume*0.5}"),
              ),
              RaisedButton(
                onPressed: (){
                  VolumeWatcher.setVolume(maxVolume*0.0);
                },
                child: Text("设置音量为${maxVolume*0.0}"),
              )
            ]),
      ),
    );
  }
}

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

0.0.1 #

  • 实现ios与android 音量监听

0.0.2 #

  • 取消控件界面默认返回内容

1.0.0 #

  • 完善功能与说明

1.0.1 #

  • 完善说明

1.1.0 #

  • 支持设置音量

example/README.md

volume_watcher_example #

Demonstrates how to use the volume_watcher plugin.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  volume_watcher: ^1.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:volume_watcher/volume_watcher.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
56
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Nov 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/volume_watcher.dart.

Run flutter format to format lib/volume_watcher.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test