fix lifecycle issue

This commit is contained in:
Fabian Freund
2026-01-01 10:09:42 +01:00
parent c82bf5b442
commit 18948b952e
2 changed files with 12 additions and 2 deletions
@@ -216,6 +216,8 @@ Stream<MlProgressData> mlProgressEvents(Ref ref) {
/// Tracks active ML model downloads
@Riverpod()
class MlDownloadState extends _$MlDownloadState {
Timer? _clearTimer;
@override
MlProgressData? build() {
ref.listen(mlProgressEventsProvider, (previous, next) {
@@ -223,7 +225,8 @@ class MlDownloadState extends _$MlDownloadState {
if (progress.type == MlProgressType.downloading) {
if (progress.status == MlProgressStatus.done) {
// Keep showing for 2 seconds after completion
Future.delayed(const Duration(seconds: 2), () {
_clearTimer?.cancel();
_clearTimer = Timer(const Duration(seconds: 2), () {
if (ref.mounted && state != null && state!.id == progress.id) {
state = null;
}
@@ -235,10 +238,17 @@ class MlDownloadState extends _$MlDownloadState {
});
});
ref.onDispose(() {
_clearTimer?.cancel();
_clearTimer = null;
});
return null;
}
void clear() {
_clearTimer?.cancel();
_clearTimer = null;
state = null;
}
}
@@ -379,7 +379,7 @@ final class MlDownloadStateProvider
}
}
String _$mlDownloadStateHash() => r'837e73d9c0f8ac5c25e075417b22ff16cfcdf818';
String _$mlDownloadStateHash() => r'a6e2612770878a9fc5ca6800665698c6335a047e';
/// Tracks active ML model downloads