fix(alarm): defer the Dart fade-in until the native handoff confirms
Build & Deploy PluriWave / Análisis de código (push) Successful in 37s
Build & Deploy PluriWave / Build APK + AAB release (push) Successful in 1m50s

The native service and the Flutter player each ran their own 5%-to-
target fade-in, and both could drive audible volume at the handoff,
producing a jump or ramp reset. The Dart ramp now starts exactly once
from the handoff-confirmation path: the player still pre-starts at 5%,
and _confirmarAudioFlutterListo() starts the ramp in a finally block
so it runs whether the native confirmation succeeds or fails — the
alarm can never stay stuck at 5% if the native side is already gone.

Work unit 3/3 of alarm-volume-ramp-restore (fade-in dedup).
This commit is contained in:
2026-07-11 09:57:06 +02:00
parent a6e1177752
commit 66a19525bd
4 changed files with 193 additions and 14 deletions
+18
View File
@@ -30,6 +30,18 @@ class FakePuertoAlarmasAndroid implements PuertoAlarmasAndroid {
/// could not otherwise produce.
bool fallaProgramar = false;
/// Test-only gate (Slice 3: fade-in dedup at handoff). When set,
/// [confirmarAudioFlutter] suspends on this completer before resolving,
/// letting a test observe the pre-confirm state deterministically instead
/// of racing real stream/timer scheduling. Complete it to let the call
/// proceed.
Completer<void>? puertaConfirmarAudioFlutter;
/// Test-only failure switch (Slice 3 edge case): when true,
/// [confirmarAudioFlutter] throws after the gate above (if any) resolves,
/// simulating a dead/never-there native channel at handoff.
bool fallaConfirmarAudioFlutter = false;
/// Simulates a native -> Flutter `alarmFired` MethodChannel event.
void emitirEvento(EventoAlarmaAndroid evento) => _eventos.add(evento);
@@ -64,6 +76,12 @@ class FakePuertoAlarmasAndroid implements PuertoAlarmasAndroid {
@override
Future<void> confirmarAudioFlutter(String alarmaId) async {
if (puertaConfirmarAudioFlutter != null) {
await puertaConfirmarAudioFlutter!.future;
}
if (fallaConfirmarAudioFlutter) {
throw StateError('fake confirmarAudioFlutter failure');
}
detenidas.add(alarmaId);
}