浏览代码

Ensure that favorites are parsed from fetched collections

Vishnu Mohandas 4 年之前
父节点
当前提交
0c48d83384
共有 2 个文件被更改,包括 10 次插入2 次删除
  1. 8 1
      lib/services/favorites_service.dart
  2. 2 1
      lib/ui/collections_gallery_widget.dart

+ 8 - 1
lib/services/favorites_service.dart

@@ -71,8 +71,15 @@ class FavoritesService {
     }
   }
 
-  Collection getFavoritesCollection() {
+  Future<Collection> getFavoritesCollection() async {
     if (!_preferences.containsKey(_favoritesCollectionIDKey)) {
+      final collections = _collectionsService.getOwnedCollections();
+      for (final collection in collections) {
+        if (collection.type == CollectionType.favorites) {
+          await _preferences.setInt(_favoritesCollectionIDKey, collection.id);
+          return collection;
+        }
+      }
       return null;
     }
     return _collectionsService

+ 2 - 1
lib/ui/collections_gallery_widget.dart

@@ -114,7 +114,8 @@ class _CollectionsGalleryWidgetState extends State<CollectionsGalleryWidget> {
     });
     if (favorites.length > 0) {
       collections.add(CollectionWithThumbnail(
-          FavoritesService.instance.getFavoritesCollection(), favorites[0]));
+          await FavoritesService.instance.getFavoritesCollection(),
+          favorites[0]));
     }
     return CollectionItems(folders, collections);
   }