Se agrego el sdk para el pda de honeywell
This commit is contained in:
@@ -1,43 +1,92 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:vibration/vibration.dart';
|
||||
|
||||
class FeedbackService {
|
||||
FeedbackService() : _player = AudioPlayer() {
|
||||
_player.setReleaseMode(ReleaseMode.stop);
|
||||
FeedbackService() {
|
||||
_configurePlayers();
|
||||
}
|
||||
|
||||
final AudioPlayer _player;
|
||||
final AudioPlayer _scanPlayer = AudioPlayer();
|
||||
final AudioPlayer _successPlayer = AudioPlayer();
|
||||
final AudioPlayer _warningPlayer = AudioPlayer();
|
||||
|
||||
static final AudioContext _loudContext = AudioContext(
|
||||
android: AudioContextAndroid(
|
||||
isSpeakerphoneOn: true,
|
||||
audioMode: AndroidAudioMode.normal,
|
||||
contentType: AndroidContentType.sonification,
|
||||
usageType: AndroidUsageType.alarm,
|
||||
audioFocus: AndroidAudioFocus.gain,
|
||||
),
|
||||
iOS: AudioContextIOS(
|
||||
category: AVAudioSessionCategory.playback,
|
||||
options: {
|
||||
AVAudioSessionOptions.mixWithOthers,
|
||||
AVAudioSessionOptions.duckOthers,
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> _configurePlayers() async {
|
||||
for (final player in [_scanPlayer, _successPlayer, _warningPlayer]) {
|
||||
await player.setReleaseMode(ReleaseMode.stop);
|
||||
await player.setPlayerMode(PlayerMode.lowLatency);
|
||||
await player.setVolume(1.0);
|
||||
await player.setAudioContext(_loudContext);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> onCodeDetected() async {
|
||||
await Future.wait([
|
||||
_play('sounds/scan.wav'),
|
||||
_vibratePattern(const [0, 40]),
|
||||
_play(_scanPlayer, 'sounds/scan.wav'),
|
||||
_vibratePattern(const [0, 80]),
|
||||
HapticFeedback.mediumImpact(),
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> onSuccess() async {
|
||||
await Future.wait([
|
||||
_play('sounds/success.wav'),
|
||||
_vibratePattern(const [0, 90, 70, 140]),
|
||||
_playSuccessSequence(),
|
||||
_vibratePattern(const [0, 120, 60, 180]),
|
||||
HapticFeedback.heavyImpact(),
|
||||
]);
|
||||
await HapticFeedback.heavyImpact();
|
||||
}
|
||||
|
||||
Future<void> onWarning() async {
|
||||
await Future.wait([
|
||||
_play('sounds/warning.wav'),
|
||||
_vibratePattern(const [0, 120, 80, 120, 80, 120]),
|
||||
_playWarningSequence(),
|
||||
_vibratePattern(const [0, 180, 80, 180, 80, 220]),
|
||||
HapticFeedback.heavyImpact(),
|
||||
]);
|
||||
await HapticFeedback.mediumImpact();
|
||||
}
|
||||
|
||||
Future<void> _play(String asset) async {
|
||||
Future<void> _playSuccessSequence() async {
|
||||
await _play(_successPlayer, 'sounds/success.wav');
|
||||
if (!kIsWeb && Platform.isAndroid) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 120));
|
||||
await _play(_successPlayer, 'sounds/success.wav');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _playWarningSequence() async {
|
||||
for (var i = 0; i < 2; i++) {
|
||||
await _play(_warningPlayer, 'sounds/warning.wav');
|
||||
if (i == 0) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 140));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _play(AudioPlayer player, String asset) async {
|
||||
try {
|
||||
await _player.stop();
|
||||
await _player.play(AssetSource(asset));
|
||||
await player.stop();
|
||||
await player.play(AssetSource(asset));
|
||||
} catch (_) {
|
||||
// Ignore audio errors on devices without speaker routing.
|
||||
await SystemSound.play(SystemSoundType.alert);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +100,7 @@ class FeedbackService {
|
||||
final intensities = pattern
|
||||
.asMap()
|
||||
.entries
|
||||
.map((entry) => entry.key.isOdd ? 180 : 0)
|
||||
.map((entry) => entry.key.isOdd ? 255 : 0)
|
||||
.toList();
|
||||
await Vibration.vibrate(
|
||||
pattern: pattern,
|
||||
@@ -62,11 +111,15 @@ class FeedbackService {
|
||||
|
||||
await Vibration.vibrate(pattern: pattern);
|
||||
} catch (_) {
|
||||
await HapticFeedback.selectionClick();
|
||||
await HapticFeedback.heavyImpact();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> dispose() async {
|
||||
await _player.dispose();
|
||||
await Future.wait([
|
||||
_scanPlayer.dispose(),
|
||||
_successPlayer.dispose(),
|
||||
_warningPlayer.dispose(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user