PickedFileInfo.fromXFile constructor

PickedFileInfo.fromXFile(
  1. XFile file, {
  2. String? mimeType,
})

Wraps an XFile (from image_picker) in a PickedFileInfo. Reads length synchronously from the underlying File — fine for local paths.

Implementation

factory PickedFileInfo.fromXFile(XFile file, {String? mimeType}) {
  final int dot = file.name.lastIndexOf('.');
  final String? ext = dot > -1 && dot < file.name.length - 1
      ? file.name.substring(dot + 1)
      : null;
  return PickedFileInfo(
    name: file.name,
    path: file.path,
    sizeBytes: File(file.path).lengthSync(),
    extension: ext,
    mimeType: mimeType,
  );
}