Skip to content

Commit 18948b9

Browse files
committed
fix lifecycle issue
1 parent c82bf5b commit 18948b9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

app/lib/features/geckoview/domain/providers.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,17 @@ Stream<MlProgressData> mlProgressEvents(Ref ref) {
216216
/// Tracks active ML model downloads
217217
@Riverpod()
218218
class MlDownloadState extends _$MlDownloadState {
219+
Timer? _clearTimer;
220+
219221
@override
220222
MlProgressData? build() {
221223
ref.listen(mlProgressEventsProvider, (previous, next) {
222224
next.whenData((progress) {
223225
if (progress.type == MlProgressType.downloading) {
224226
if (progress.status == MlProgressStatus.done) {
225227
// Keep showing for 2 seconds after completion
226-
Future.delayed(const Duration(seconds: 2), () {
228+
_clearTimer?.cancel();
229+
_clearTimer = Timer(const Duration(seconds: 2), () {
227230
if (ref.mounted && state != null && state!.id == progress.id) {
228231
state = null;
229232
}
@@ -235,10 +238,17 @@ class MlDownloadState extends _$MlDownloadState {
235238
});
236239
});
237240

241+
ref.onDispose(() {
242+
_clearTimer?.cancel();
243+
_clearTimer = null;
244+
});
245+
238246
return null;
239247
}
240248

241249
void clear() {
250+
_clearTimer?.cancel();
251+
_clearTimer = null;
242252
state = null;
243253
}
244254
}

app/lib/features/geckoview/domain/providers.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)