Volume Controller
Control and observe the system volume on Android, iOS, macOS, Windows, and Linux.
Requirements
- Flutter
>=3.38.0 - Dart
^3.10.0
The iOS plugin uses the scene lifecycle APIs introduced for Flutter plugins in Flutter 3.38.
Supported Platforms
| Platform | Supported |
|---|---|
| Android | ✅ |
| iOS | ✅ |
| macOS | ✅ |
| Windows | ✅ |
| Linux | ✅ |
Notes
- iOS volume control must be tested on a real device. The simulator does not support system volume control.
showSystemUIis supported on Android and iOS only.- On Android and iOS,
isMuted()treats volume0as muted, andsetMute(false)restores the previous volume saved by the plugin.
Variables
ShowSystemUI
Show or hide the volume system UI. The default value is true. Supported on iOS and Android only.
VolumeController.instance.showSystemUI = true;
Functions
GetVolume
Get the current system volume.
double volume = await VolumeController.instance.getVolume();
SetVolume
Set the system volume. The input should be in the range 0.0 to 1.0.
await VolumeController.instance.setVolume(double volume);
AddListener
Add a listener to monitor system volume changes.
fetchInitialVolume: This parameter is optional and is used to fetch the initial volume when the listener is added. The default value istrue.
VolumeController.instance.addListener((volume) {
// Do something with the volume
}, fetchInitialVolume: true);
RemoveListener
Remove the volume listener.
VolumeController.instance.removeListener();
IsMuted
Check whether the system is muted. On iOS and Android, this checks whether the volume level is 0.
bool isMuted = await VolumeController.instance.isMuted();
SetMute
Mute or unmute the system volume. On iOS and Android, this sets the volume level to 0 and restores the previous volume level when unmuted.
await VolumeController.instance.setMute(bool mute);