ensureLeadingSlash function

String ensureLeadingSlash(
  1. String path
)

Prepends a forward slash to path if it doesn't start with one already.

Returns path unchanged if it already starts with a forward slash.

Implementation

String ensureLeadingSlash(String path) {
  if (!path.startsWith('/')) {
    return '/$path';
  }
  return path;
}