Resonance is volume and vibration controller plugin. This plugin based on the Android volume and vibration controller. The plugin let you control volume without user interaction and allow customable vibration pattern.
Get the latest plugin directly from Pub.
- Get current volume level
- Get max volume level
- Set volume level
- Set max volume level
- Set mute volume level
- Showing volume UI (Android only)
- Volume stream types (music, notification, alarm, etc.)
- Listenable volume level change
- Create Vibration
- Create Pattern Vibration
- Cancel Pattern Vibration
- Get current volume level
var crntVol = await Resonance.volumeGetCurrentLevel(streamType: StreamType.alarm);
print(crntVol);
- Set volume level
var crntVol = await Resonance.volumeSetLevel(0.5, showVolumeUI: true);
print(crntVol);
- Add volume listener
double _volumeLevel = 0;
@override
void initState() {
// Add listener
Resonance().addVolumeListener((volume) {
setState(() {
_volumeLevel = volume;
});
});
super.initState();
}
@override
void dispose() {
// Remove listener
Resonance().removeVolumeListener();
super.dispose();
}
- Create one-shot vibration by certain duration
await Resonance.vibrate(duration: const Duration(milliseconds: 1000));
- Create pattern vibration
await Resonance.vibratePattern(
[0, 400, 1000, 600, 1000, 800],
amplitude: 255, // Default: null
repeat: false, // Default: false
);
- Cancel active pattern vibration
await Resonance.vibrationCancel();
Version 1.0.3 is released
Only work for Android.
Return | Method | Description |
---|---|---|
Future<double> | volumeGetCurrentLevel(StreamType streamType) | Returns device's current volume level. |
Future<double> | volumeGetMaxLevel(StreamType streamType) | Returns device's maximum volume level. |
Future<double> | volumeSetLevel(double volumeValue, StreamType streamType, bool showVolumeUI) | Set device's volume level to given volumeValue parameter and returns current volume level. |
Future<double> | volumeSetMaxLevel(StreamType streamType, bool showVolumeUI) | Set device's volume level to maximum and returns current volume level. |
Future<double> | volumeSetMuteLevel(StreamType streamType, bool showVolumeUI) | Set device's volume level to minimum or muted and returns current volume level. |
StreamSubscription<double> | addVolumeListener(Function(double volume) function) | Add volume change listener to handle given callback. |
void | removeVolumeListener() | Cancel listener from broadcast stream |
Future<bool> | vibrate(Duration? duration) | Create vibration by certain duration, default duration is 400ms and returns boolean status. |
Future<bool> | vibratePattern(List<int> pattern, int? amplitude, bool repeat,) | Create vibration by given custom pattern, amplitude, and repeat. |
Future<bool> | vibrationCancel() | Cancel any active repeated vibration and returns boolean status. |
Tegar Bangun Suganda
@canaryv8 (Twitter)
@suganda8 (Github)
resonance
MIT License
Copyright (c) 2022 Tegar Bangun Suganda (OVERMIND)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.