Skip to content

Commit 5aa9e50

Browse files
committed
🚀 Integrate lastModified to sort path entities by modified date
1 parent ff7bcfe commit 5aa9e50

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

lib/src/delegates/sort_path_delegate.dart

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ class CommonSortPathDelegate extends SortPathDelegate {
2929

3030
@override
3131
void sort(List<AssetPathEntity> list) {
32+
if (list.any((AssetPathEntity e) => e.lastModified != null)) {
33+
list.sort((AssetPathEntity path1, AssetPathEntity path2) {
34+
if (path1.lastModified == null || path2.lastModified == null) {
35+
return 0;
36+
}
37+
if (path2.lastModified!.isAfter(path1.lastModified!)) {
38+
return 1;
39+
}
40+
return -1;
41+
});
42+
}
3243
list.sort((AssetPathEntity path1, AssetPathEntity path2) {
3344
if (path1.isAll) {
3445
return -1;
@@ -48,7 +59,7 @@ class CommonSortPathDelegate extends SortPathDelegate {
4859
if (_isScreenShot(path2)) {
4960
return 1;
5061
}
51-
return otherSort(path1, path2);
62+
return 0;
5263
});
5364
}
5465

@@ -57,11 +68,10 @@ class CommonSortPathDelegate extends SortPathDelegate {
5768
}
5869

5970
bool _isCamera(AssetPathEntity entity) {
60-
return entity.name.toUpperCase() == 'camera'.toUpperCase();
71+
return entity.name == 'Camera';
6172
}
6273

6374
bool _isScreenShot(AssetPathEntity entity) {
64-
return entity.name.toUpperCase() == 'screenshots'.toUpperCase() ||
65-
entity.name.toUpperCase() == 'screenshot'.toUpperCase();
75+
return entity.name == 'Screenshots' || entity.name == 'Screenshot';
6676
}
6777
}

lib/src/provider/asset_picker_provider.dart

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,18 +268,17 @@ class DefaultAssetPickerProvider
268268
Future<void> getAssetPathList() async {
269269
// Initial base options.
270270
// Enable need title for audios and image to get proper display.
271-
final FilterOptionGroup options = FilterOptionGroup()
272-
..setOption(
273-
AssetType.audio,
274-
const FilterOption(needTitle: true),
275-
)
276-
..setOption(
277-
AssetType.image,
278-
const FilterOption(
279-
needTitle: true,
280-
sizeConstraint: SizeConstraint(ignoreSize: true),
281-
),
282-
);
271+
final FilterOptionGroup options = FilterOptionGroup(
272+
imageOption: const FilterOption(
273+
needTitle: true,
274+
sizeConstraint: SizeConstraint(ignoreSize: true),
275+
),
276+
audioOption: const FilterOption(
277+
needTitle: true,
278+
sizeConstraint: SizeConstraint(ignoreSize: true),
279+
),
280+
containsPathModified: true,
281+
);
283282

284283
// Merge user's filter option into base options if it's not null.
285284
if (filterOptions != null) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ dependencies:
1212
sdk: flutter
1313

1414
extended_image: ^4.0.0
15-
photo_manager: ^1.0.6
15+
photo_manager: ^1.1.0
1616
provider: ^5.0.0
1717
video_player: ^2.1.0

0 commit comments

Comments
 (0)