Fix reload issue within collections

This commit is contained in:
Vishnu Mohandas 2020-11-16 13:49:47 +05:30
parent f5ae71ca17
commit 71f6db7d2c
2 changed files with 14 additions and 25 deletions

View file

@ -35,28 +35,16 @@ class _CollectionPageState extends State<CollectionPage> {
_selectedFiles,
collection: widget.collection,
),
body: _getGallery(),
);
}
Widget _getGallery() {
return FutureBuilder<List<File>>(
future: FilesDB.instance.getAllInCollection(widget.collection.id),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Gallery(
syncLoader: () => snapshot.data,
reloadEvent: Bus.instance
.on<CollectionUpdatedEvent>()
.where((event) => event.collectionID == widget.collection.id),
tagPrefix: widget.tagPrefix,
selectedFiles: _selectedFiles,
);
} else if (snapshot.hasError) {
return Text(snapshot.error.toString());
}
return loadWidget;
},
body: Gallery(
asyncLoader: (_, __) =>
FilesDB.instance.getAllInCollection(widget.collection.id),
shouldLoadAll: true,
reloadEvent: Bus.instance
.on<CollectionUpdatedEvent>()
.where((event) => event.collectionID == widget.collection.id),
tagPrefix: widget.tagPrefix,
selectedFiles: _selectedFiles,
),
);
}
}

View file

@ -19,6 +19,7 @@ import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
class Gallery extends StatefulWidget {
final List<File> Function() syncLoader;
final Future<List<File>> Function(File lastFile, int limit) asyncLoader;
final bool shouldLoadAll;
final Stream<Event> reloadEvent;
final SelectedFiles selectedFiles;
final String tagPrefix;
@ -27,6 +28,7 @@ class Gallery extends StatefulWidget {
Gallery({
this.syncLoader,
this.asyncLoader,
this.shouldLoadAll = false,
this.reloadEvent,
this.headerWidget,
@required this.selectedFiles,
@ -70,7 +72,7 @@ class _GalleryState extends State<Gallery> {
widget.selectedFiles.addListener(() {
setState(() {});
});
if (widget.asyncLoader == null) {
if (widget.asyncLoader == null || widget.shouldLoadAll) {
_hasLoadedAll = true;
}
_itemPositionsListener.itemPositions.addListener(_updateScrollbar);
@ -202,9 +204,8 @@ class _GalleryState extends State<Gallery> {
_isLoadingNext = false;
if (files.length < kLoadLimit) {
_hasLoadedAll = true;
} else {
_files.addAll(files);
}
_files.addAll(files);
});
});
}