flutter / flutter/flutter

Preserve file date (mtime) for images/files picked

Open
#160,934 1 comment 1 reaction 0 assignees View on GitHub
c: new feature c: proposal p: image_picker P2 package platform-android team-android triaged-android
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Use case

When picking a file or files, it's often useful to know when the original file was created/edited. This allows features like sorting by date as well as by file name. Unfortunately, at least on Android, the last edit date (mtime) of the temp file returned from image_picker has the date/time of when the file was selected and I haven't yet found any way to access the original file's last edit date.

### Proposal

final XFile? tmpFile = await ImagePicker().pickImage(
source: ImageSource.gallery,
preserveOriginalMtime = true,
);
if (tmpFile == null) {
return null;
}
final lastModifiedObject = await tmpFile.lastModified();
// prints modified time of original file instead of "right now"
print("Last Modified: " + lastModifiedObject.toString());

/******************************/

// Implementation, could be approximated by something like
if (preserveOriginalMtime == true) {
await touch(newTmpFile, await fileMtime(originalFile));
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.