m3_lightmeter/lib/data/haptics_service.dart

23 lines
656 B
Dart
Raw Permalink Normal View History

import 'package:vibration/vibration.dart';
class HapticsService {
const HapticsService();
2023-01-26 15:03:48 +00:00
Future<void> quickVibration() async => _tryVibrate(duration: 25, amplitude: 96);
Future<void> responseVibration() async => _tryVibrate(duration: 50, amplitude: 128);
2023-05-05 21:08:20 +00:00
Future<void> errorVibration() async => _tryVibrate(duration: 100, amplitude: 128);
Future<void> _tryVibrate({required int duration, required int amplitude}) async {
if (await _canVibrate()) {
2023-05-05 21:08:20 +00:00
await Vibration.vibrate(
duration: duration,
amplitude: amplitude,
);
}
}
Future<bool> _canVibrate() async => await Vibration.hasVibrator() ?? false;
}