randomTemporaryDirectory function

Directory randomTemporaryDirectory({
  1. String? debugName,
  2. bool deleteAfterTest = true,
})

Returns a random temporary directory path.

The directory will be inside Directory.systemTemp. This method does not create the directory or otherwise change state of the file system.

In browsers, the method returns null.

You can optionally specify a debugName.

If this method is called inside a test and deleteAfterTest is true, the directory will be deleted after the test finishes (if it exists).

Example

import 'package:os/os_memory.dart';
import 'package:test/test_environment.dart';

void main() {
  test(() {
    final directory = randomTemporaryDirectory();
    // ...
  });

  test(() {
    final directory = randomTemporaryDirectory();
    // ...
  });
}

Implementation

Directory randomTemporaryDirectory({
  String? debugName,
  bool deleteAfterTest = true,
}) {
  return randomTemporaryDirectoryImpl(
    debugName: debugName,
    deleteAfterTest: deleteAfterTest,
  );
}