Modified code to get the memories count before building the Gallery to set height of gallery

This commit is contained in:
ashilkn 2023-03-23 17:31:30 +05:30
parent fbf3b35c57
commit 4f8997cb2b

View file

@ -384,18 +384,9 @@ class _AddToLocationGalleryWidgetState
@override
Widget build(BuildContext context) {
return SizedBox(
height: 6000,
child: Gallery(
key: ValueKey(_selectedRadius()),
loadingWidget: const SizedBox.shrink(),
disableScroll: true,
asyncLoader: (
creationStartTime,
creationEndTime, {
limit,
asc,
}) async {
final selectedRadius = _selectedRadius().toInt();
late final int memoryCount;
Future<FileLoadResult> filterFiles() async {
final FileLoadResult result = await fileLoadResult;
//wait for ignored files to be removed after init
await removeIgnoredFiles;
@ -410,24 +401,51 @@ class _AddToLocationGalleryWidgetState
return !LocationService.instance.isFileInsideLocationTag(
InheritedLocationTagData.of(context).coordinates,
[f.location!.latitude!, f.location!.longitude!],
_selectedRadius().toInt(),
selectedRadius,
);
});
dev.log(
"Time taken to get all files in a location tag: ${stopWatch.elapsedMilliseconds} ms");
"Time taken to get all files in a location tag: ${stopWatch.elapsedMilliseconds} ms",
);
stopWatch.stop();
// if (!result.hasMore) {
memoryCount = copyOfFiles.length;
widget.memoriesCountNotifier.value = copyOfFiles.length;
// }
return FileLoadResult(
return Future.value(
FileLoadResult(
copyOfFiles,
result.hasMore,
),
);
}
return FutureBuilder(
key: ValueKey(selectedRadius),
builder: (context, snapshot) {
if (snapshot.hasData) {
return SizedBox(
height: 4000,
child: Gallery(
key: ValueKey(selectedRadius),
loadingWidget: const SizedBox.shrink(),
disableScroll: true,
asyncLoader: (
creationStartTime,
creationEndTime, {
limit,
asc,
}) async {
return snapshot.data as FileLoadResult;
},
tagPrefix: "Add location",
shouldCollateFilesByDay: false,
),
);
} else {
return const SizedBox.shrink();
}
},
future: filterFiles(),
);
}
double _selectedRadius() {