getUniqueFilename method

Future<String> getUniqueFilename({
  1. int length = 30,
  2. int? maxTries,
  3. String? prefix,
  4. String? extension,
  5. Context? pathContext,
})

Get a new random and unique filename in this Directory.

  • length - The length of the unique filename. The total length of the name of the returned file is length + (prefix?.length ?? 0) + (extension?.length ?? 0).

  • maxTries - How many times a new filename should be generated until a unique one is found in the Directory. If this parameter is set to null, then new filenames will be generated until a unique one is found. If this parameter is set to a fixed number and no unique name can be found, then an OutOfTriesException gets thrown.

  • prefix - The prefix for the unique filename.

  • extension - The file extension.

See also getUniqueFilenameSync

Implementation

Future<String> getUniqueFilename({
  int length = 30,
  int? maxTries,
  String? prefix,
  String? extension,
  lib_path.Context? pathContext,
}) async {
  pathContext ??= lib_path.context;

  final names = await get_unique_file_impl.getNamesInDir(
    directory: this,
    pathContext: pathContext,
  );

  return get_unique_file_impl.getUniqueFilename(
    currentDir: this,
    length: length,
    maxTries: maxTries,
    namesInDir: names,
    extension: extension,
    prefix: prefix,
  );
}