From 0e0a472de18edc3eb52a24221682914b74f56190 Mon Sep 17 00:00:00 2001 From: shenlong <139912620+shenlong-tanwen@users.noreply.github.com> Date: Wed, 10 Jan 2024 15:31:54 +0000 Subject: [PATCH] fix(mobile): ensure notifier is mounted before updating state (#6308) Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> --- mobile/lib/modules/album/providers/album.provider.dart | 6 +++++- .../lib/modules/album/providers/shared_album.provider.dart | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mobile/lib/modules/album/providers/album.provider.dart b/mobile/lib/modules/album/providers/album.provider.dart index 5618ea91d4..2522e97bcc 100644 --- a/mobile/lib/modules/album/providers/album.provider.dart +++ b/mobile/lib/modules/album/providers/album.provider.dart @@ -16,7 +16,11 @@ class AlbumNotifier extends StateNotifier> { final query = db.albums .filter() .owner((q) => q.isarIdEqualTo(Store.get(StoreKey.currentUser).isarId)); - query.findAll().then((value) => state = value); + query.findAll().then((value) { + if (mounted) { + state = value; + } + }); _streamSub = query.watch().listen((data) => state = data); } final AlbumService _albumService; diff --git a/mobile/lib/modules/album/providers/shared_album.provider.dart b/mobile/lib/modules/album/providers/shared_album.provider.dart index b864e855fb..83eed53010 100644 --- a/mobile/lib/modules/album/providers/shared_album.provider.dart +++ b/mobile/lib/modules/album/providers/shared_album.provider.dart @@ -12,7 +12,11 @@ import 'package:isar/isar.dart'; class SharedAlbumNotifier extends StateNotifier> { SharedAlbumNotifier(this._albumService, Isar db) : super([]) { final query = db.albums.filter().sharedEqualTo(true).sortByCreatedAtDesc(); - query.findAll().then((value) => state = value); + query.findAll().then((value) { + if (mounted) { + state = value; + } + }); _streamSub = query.watch().listen((data) => state = data); }