From a15f7a0db64d780410a90302dc51080fdb8b5030 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Sat, 25 Sep 2021 13:45:02 +0800 Subject: [PATCH] Fix new provider being created instead of modified --- lib/entity/album.dart | 6 ++++-- lib/use_case/add_to_album.dart | 2 +- lib/use_case/remove.dart | 2 +- lib/widget/album_browser.dart | 10 +++++----- lib/widget/viewer_detail_pane.dart | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/entity/album.dart b/lib/entity/album.dart index 245f5efa..c2692098 100644 --- a/lib/entity/album.dart +++ b/lib/entity/album.dart @@ -297,7 +297,7 @@ class AlbumAppDbDataSource implements AlbumDataSource { }).reduce((value, element) => value + element); return entries.first.album.copyWith( lastUpdated: OrNull(null), - provider: AlbumStaticProvider( + provider: AlbumStaticProvider.of(entries.first.album).copyWith( items: items, ), ); @@ -433,7 +433,9 @@ Future _cacheAlbum( pair.item1, album.copyWith( lastUpdated: OrNull(null), - provider: AlbumStaticProvider(items: pair.item2), + provider: AlbumStaticProvider.of(album).copyWith( + items: pair.item2, + ), )))); } else { entries.add(AppDbAlbumEntry(path, 0, album)); diff --git a/lib/use_case/add_to_album.dart b/lib/use_case/add_to_album.dart index 7948e1c9..5a26c853 100644 --- a/lib/use_case/add_to_album.dart +++ b/lib/use_case/add_to_album.dart @@ -12,7 +12,7 @@ class AddToAlbum { UpdateAlbum(albumRepo)( account, album.copyWith( - provider: AlbumStaticProvider( + provider: AlbumStaticProvider.of(album).copyWith( items: makeDistinctAlbumItems([ ...items, ...AlbumStaticProvider.of(album).items, diff --git a/lib/use_case/remove.dart b/lib/use_case/remove.dart index 2e804d7d..b5293bcb 100644 --- a/lib/use_case/remove.dart +++ b/lib/use_case/remove.dart @@ -96,7 +96,7 @@ class _CleanUpAlbums { await UpdateAlbum(albumRepo)( account, a.copyWith( - provider: AlbumStaticProvider( + provider: AlbumStaticProvider.of(a).copyWith( items: newItems, ), )); diff --git a/lib/widget/album_browser.dart b/lib/widget/album_browser.dart index 39b42aa5..3fe46903 100644 --- a/lib/widget/album_browser.dart +++ b/lib/widget/album_browser.dart @@ -325,7 +325,7 @@ class _AlbumBrowserState extends State final albumRepo = AlbumRepo(AlbumCachedDataSource()); final newAlbum = _album!.copyWith( - provider: AlbumStaticProvider( + provider: AlbumStaticProvider.of(_album!).copyWith( items: newItems, ), ); @@ -449,7 +449,7 @@ class _AlbumBrowserState extends State _editAlbum = _editAlbum!.copyWith( sortProvider: const AlbumNullSortProvider(), // save the current order - provider: AlbumStaticProvider( + provider: AlbumStaticProvider.of(_editAlbum!).copyWith( items: _sortedItems, ), ); @@ -467,7 +467,7 @@ class _AlbumBrowserState extends State return; } _editAlbum = _editAlbum!.copyWith( - provider: AlbumStaticProvider( + provider: AlbumStaticProvider.of(_editAlbum!).copyWith( items: [ AlbumLabelItem(text: value), ..._sortedItems, @@ -492,7 +492,7 @@ class _AlbumBrowserState extends State } _sortedItems[index] = AlbumLabelItem(text: value); _editAlbum = _editAlbum!.copyWith( - provider: AlbumStaticProvider( + provider: AlbumStaticProvider.of(_editAlbum!).copyWith( items: _sortedItems, ), ); @@ -624,7 +624,7 @@ class _AlbumBrowserState extends State return e[0]; }).toList(); final propagateAlbum = album.copyWith( - provider: AlbumStaticProvider( + provider: AlbumStaticProvider.of(album).copyWith( items: propagateItems, ), ); diff --git a/lib/widget/viewer_detail_pane.dart b/lib/widget/viewer_detail_pane.dart index b6c639e4..ff03fcae 100644 --- a/lib/widget/viewer_detail_pane.dart +++ b/lib/widget/viewer_detail_pane.dart @@ -308,7 +308,7 @@ class _ViewerDetailPaneState extends State { await UpdateAlbum(albumRepo)( widget.account, widget.album!.copyWith( - provider: AlbumStaticProvider( + provider: AlbumStaticProvider.of(widget.album!).copyWith( items: newItems, ), ));