1

I am using the following code snippet to attempt to retrieve the modified time of a file:

import 'dart:io';
import 'package:image_picker/image_picker.dart';

final picker = ImagePicker();
final pickedFile = await picker.getVideo(source: ImageSource.gallery);
final file = File(pickedFile.path);
print("file modified time: ${file.lastModifiedSync().toIso8601String()}");

Whenever I run the the above snippet, regardless of the file, it prints the current dateTime as opposed to the file's modified dataTime

Amy
  • 184
  • 3
  • 9

2 Answers2

2

The way the image_picker work is it creates a temporary copy of the file which you are about to upload in your app. With this implementation, the "current date" you are mentioning is the logically the file's "last modified date" (or creation date). So for now, you may not be able to retrieve it using this plugin.

However, with Flutter's Platform Channels, you should be able to retrieve the file's attributes, eg. for Android, using BasicFileAttributes in native code.

For example in Android:

File file = ...;
BasicFileAttributes attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
long lastModifiedAt = attr.lastModifiedTime();

Then using platform channels, you can pass the data like this to Flutter:

result.success(lastModifiedAt)

References

Joshua de Guzman
  • 1,880
  • 7
  • 22
0

I don't believe this information is available, unfortunately (at least on Android, not sure about iOS)

Pierre
  • 179
  • 1
  • 2
  • 9