fix(alarm): handle snooze reschedule failures instead of silently dropping them
posponerAlarma() and posponerProximaDesdePreaviso() called the native scheduler with no error handling, unlike guardarAlarma(). When the native call failed (e.g. revoked exact-alarm permission), the exception escaped before notifyListeners() ran, leaving the alarm list stuck on stale data with no real alarm scheduled and no snooze countdown notification. Both methods now mirror guardarAlarma()'s pattern: permission pre-check, try/catch into _error, and an unconditional notifyListeners() so the UI always reflects the outcome. Failures surface via SnackBar in the ringing screen and in app.dart's postpone-next handler.
This commit is contained in:
@@ -192,6 +192,7 @@ class EstadoAlarmas extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> posponerAlarma(AlarmaMusical alarma, int minutos) async {
|
||||
_error = null;
|
||||
final ejecucion =
|
||||
alarma.snoozeOrigen ?? alarma.proximaEjecucion ?? DateTime.now();
|
||||
debugPrint(
|
||||
@@ -205,8 +206,14 @@ class EstadoAlarmas extends ChangeNotifier {
|
||||
);
|
||||
_aplicar(config);
|
||||
final actualizada = _buscarAlarma(alarma.id);
|
||||
if (actualizada != null) {
|
||||
await android.programar(actualizada);
|
||||
try {
|
||||
if (actualizada != null) {
|
||||
await _solicitarPermisosNecesariosParaAlarma();
|
||||
await android.programar(actualizada);
|
||||
}
|
||||
} catch (e) {
|
||||
_error =
|
||||
'Alarma pospuesta, pero Android no pudo reprogramarla todavía: $e';
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -216,6 +223,7 @@ class EstadoAlarmas extends ChangeNotifier {
|
||||
int minutos,
|
||||
DateTime ejecucion,
|
||||
) async {
|
||||
_error = null;
|
||||
final seguros = _snoozeSeguro(minutos);
|
||||
final snoozeHasta = ejecucion.add(Duration(minutes: seguros));
|
||||
debugPrint(
|
||||
@@ -229,8 +237,14 @@ class EstadoAlarmas extends ChangeNotifier {
|
||||
);
|
||||
_aplicar(config);
|
||||
final actualizada = _buscarAlarma(alarma.id);
|
||||
if (actualizada != null) {
|
||||
await android.programar(actualizada);
|
||||
try {
|
||||
if (actualizada != null) {
|
||||
await _solicitarPermisosNecesariosParaAlarma();
|
||||
await android.programar(actualizada);
|
||||
}
|
||||
} catch (e) {
|
||||
_error =
|
||||
'Alarma pospuesta, pero Android no pudo reprogramarla todavía: $e';
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user