Improve performance of group building function by not eagerly computing each group header's title and instead, offload it to the GroupHeaderWidget to compute lazily when it's built

This commit is contained in:
ashilkn
2025-07-04 12:31:12 +05:30
parent 23728107a3
commit fd05961303
2 changed files with 4 additions and 10 deletions

View File

@@ -25,12 +25,10 @@ class GalleryGroups {
final bool sortOrderAsc;
final double widthAvailable;
final double headerExtent;
final BuildContext context;
GalleryGroups({
required this.allFiles,
required this.groupType,
required this.widthAvailable,
required this.context,
required this.selectedFiles,
required this.tagPrefix,
this.sortOrderAsc = true,
@@ -102,7 +100,9 @@ class GalleryGroups {
builder: (context, rowIndex) {
if (rowIndex == firstIndex) {
return GroupHeaderWidget(
title: _groupIdToHeaderDataMap[groupID]!.title,
title: _groupIdToHeaderDataMap[groupID]!
.groupType
.getTitle(context, groupIDToFilesMap[groupID]!.first),
gridSize: crossAxisCount,
);
} else {
@@ -205,21 +205,15 @@ class GalleryGroups {
_groupIds.add(uuid);
_groupIdToFilesMap[uuid] = dailyFiles;
_groupIdToHeaderDataMap[uuid] = GroupHeaderData(
title: groupType.getTitle(
context,
dailyFiles.first,
),
groupType: groupType,
);
}
}
class GroupHeaderData {
final String title;
final GroupType groupType;
GroupHeaderData({
required this.title,
required this.groupType,
});
}

View File

@@ -418,6 +418,7 @@ class GalleryState extends State<Gallery> {
child: Scrollbar(
interactive: true,
child: CustomScrollView(
// physics: const BouncingScrollPhysics(),
slivers: [
FutureBuilder(
future: headerExtent,
@@ -428,7 +429,6 @@ class GalleryState extends State<Gallery> {
allFiles: _allGalleryFiles,
groupType: widget.groupType,
widthAvailable: MediaQuery.sizeOf(context).width,
context: context,
selectedFiles: widget.selectedFiles,
tagPrefix: widget.tagPrefix,
headerExtent: snapshot.data!,