fileExtensionFromPath method

String fileExtensionFromPath(
  1. String path
)

Extracts the file extension from the given file path.

Parameters:

  • path The file path to extract the extension from.

Returns:

The extracted file extension.

Implementation

String fileExtensionFromPath(String path) {
  final List<String> parts = path.split('.');

  assert(
    parts.length > 1 && parts.last.isNotEmpty,
    'Invalid file path format: $path. Path should contain a valid extension.',
  );

  return parts.last;
}