useCustomBaseDirectory static method

Future<void> useCustomBaseDirectory({
  1. required Directory baseDirectory,
  2. Directory? testDirectory,
})

If running from Flutter, the base directory will be the given baseDirectory. If running from tests, it will use the optional testDirectory, or if this is not provided, it will use the system's temp directory.

Implementation

static Future<void> useCustomBaseDirectory({
  required Directory baseDirectory,
  Directory? testDirectory,
}) async {
  if (_baseDirectory != null) return;

  if (_fileSystem == const LocalFileSystem()) {
    try {
      // Calling this just to detect if we are running from Flutter or tests.
      await getDownloadsDirectory();
      _baseDirectory = baseDirectory;
    } on MissingPluginException catch (_) {
      _baseDirectory = testDirectory ?? const LocalFileSystem().systemTempDirectory;
    }
  } else
    _baseDirectory = _fileSystem.systemTempDirectory;
}