Asset.fromPath constructor

Asset.fromPath(
  1. String filePath
)

Creates an Asset from a file path.

Extracts the necessary metadata from the file path:

  • name: filename without extension
  • extension: file extension
  • directory: containing directory name
  • fileName: complete filename with extension

Implementation

factory Asset.fromPath(String filePath) {
  final fileName = basename(filePath);
  final name = basenameWithoutExtension(filePath);
  final extension = fileName.contains('.') ? fileName.split('.').last : '';
  final directory = basename(dirname(filePath));

  return Asset(
    name: name,
    path: filePath,
    extension: extension,
    directory: directory,
    fileName: fileName,
  );
}