Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix gallery grouping for covariant file lists

ashilknf833f2fb99b4
diff --git a/mobile/apps/photos/changes/fix-trash-gallery-grouping-crash.md b/mobile/apps/photos/changes/fix-trash-gallery-grouping-crash.md
new file mode 100644
index 0000000000..5e05aca2c7
--- /dev/null
+++ b/mobile/apps/photos/changes/fix-trash-gallery-grouping-crash.md
@@ -0,0 +1 @@
+- Fixed a crash when opening Ente Trash.
diff --git a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
index 24c08828e9..2871f4a573 100644
--- a/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
+++ b/mobile/apps/photos/lib/models/gallery/gallery_groups.dart
@@ -314,7 +314,7 @@ class GalleryGroups {
if (groupType.showGroupHeader()) {
var start = 0;
for (final end in _timeGroupEndIndexes()) {
- _createNewGroup(allFiles.sublist(start, end), yearsInGroups);
+ _createNewGroup(_copyFilesInRange(start, end), yearsInGroups);
start = end;
}
} else {
@@ -324,7 +324,7 @@ class GalleryGroups {
final end = (i + 10 * crossAxisCount < allFiles.length)
? i + 10 * crossAxisCount
: allFiles.length;
- final subGroup = allFiles.sublist(i, end);
+ final subGroup = _copyFilesInRange(i, end);
_createNewGroup(subGroup, yearsInGroups);
}
}
@@ -335,6 +335,12 @@ class GalleryGroups {
stopwatch.stop();
}
+ List<EnteFile> _copyFilesInRange(int start, int end) {
+ // sublist preserves a covariant source list's runtime element type, which
+ // can reject DummyFile placeholders added by _createNewGroup.
+ return List<EnteFile>.from(allFiles.getRange(start, end));
+ }
+
List<int> _timeGroupEndIndexes() {
final ends = <int>[];
if (allFiles.isEmpty) {