isRelativePath function

bool isRelativePath(
  1. String path
)

Whether path is a relative path (no leading / and no drive letter).

Empty or whitespace-only input is treated as relative.

Example:

isRelativePath('docs/readme.md'); // true
isRelativePath('/etc/hosts'); // false
isRelativePath(r'C:\Windows'); // false

Implementation

bool isRelativePath(String path) {
  final String trimmed = path.trim();
  if (trimmed.isEmpty) return true;
  if (trimmed.startsWith('/')) return false;
  return trimmed.length < 2 || trimmed[1] != ':';
}