PickedFileInfo.fromPath constructor

PickedFileInfo.fromPath(
  1. String path, {
  2. String? name,
  3. String? mimeType,
})

Constructs from a local file path. Useful for files produced in-app (e.g. by VoiceRecorder) where there's no XFile / fp.PlatformFile wrapper.

Implementation

factory PickedFileInfo.fromPath(String path,
    {String? name, String? mimeType}) {
  final f = File(path);
  final filename = name ?? path.split('/').last;
  final dot = filename.lastIndexOf('.');
  final ext = dot > -1 && dot < filename.length - 1
      ? filename.substring(dot + 1)
      : null;
  return PickedFileInfo(
    name: filename,
    path: path,
    sizeBytes: f.lengthSync(),
    extension: ext,
    mimeType: mimeType,
  );
}