createPath static method

Future<String> createPath({
  1. required LocalDir localDir,
  2. required String subPath,
})

Allows for the easy creation of a path string.

createPath(
  localDir: LocalDir.tempDir,
  subPath: "/images",
) == "/path/to/tmp/images"

Throws a FormatException if subPath is not a valid path. Below are some invalid paths:

subPath: "@image" => throws FormatException
subPath: "../image" => throws FormatException
subPath: "~" => throws FormatException
subPath: "" => throws FormatException

Implementation

static Future<String> createPath({
  required LocalDir localDir,
  required String subPath,
}) async {
  final String localDirPath =
      "${await fetchPath(localDir)}${Platform.pathSeparator}";
  final String subPathSterile = sterilizePath(subPath);

  // Check for valid sub-path.
  if (subPathSterile.isEmpty) {
    throw FormatException("$subPath is not a valid sub-path!");
  }

  return "$localDirPath$subPathSterile";
}