aves_mio1/lib/remote/remote_sync_bus.dart.ok
FabioMich66 deb7b4c6dd
Some checks are pending
Quality check / Flutter analysis (push) Waiting to run
Quality check / CodeQL analysis (java-kotlin) (push) Waiting to run
super
2026-04-10 10:07:04 +02:00

51 lines
1.3 KiB
Text

// lib/remote/remote_sync_bus.dart
import 'package:flutter/foundation.dart';
class RemoteSyncProgress {
final String phase;
final int done;
final int total;
final bool finished;
const RemoteSyncProgress({
required this.phase,
required this.done,
required this.total,
this.finished = false,
});
double? get value => total > 0 ? done / total : null;
}
class RemoteSyncBus {
RemoteSyncBus._();
static final RemoteSyncBus instance = RemoteSyncBus._();
final ValueNotifier<RemoteSyncProgress?> notifier = ValueNotifier(null);
void start({required String phase, required int total}) {
notifier.value = RemoteSyncProgress(phase: phase, done: 0, total: total);
}
void update({required String phase, required int done, required int total}) {
notifier.value = RemoteSyncProgress(phase: phase, done: done, total: total);
}
void finish({String phase = 'Completato'}) {
final cur = notifier.value;
if (cur == null) return;
notifier.value = RemoteSyncProgress(
phase: phase,
done: cur.total,
total: cur.total,
finished: true,
);
// auto-hide dopo 1s
Future.delayed(const Duration(seconds: 1), () {
if (notifier.value?.finished == true) notifier.value = null;
});
}
void clear() => notifier.value = null;
}