create method
Creates a temporary file in the systems temp directory. @param subdirectory - the directory (under the temp file system) to place the file in. @param prefix - an optional prefix to prepend to the randomly generated filename.
Example: File tmpRecording = await TempFiles() .create(TempFileLocations.RECORDINGS);
Implementation
Future<File> create(TempFileLocations location, [String prefix = '']) async {
var derivedPath = '${Directory.systemTemp.path}'
'/'
'$_rootDir'
'/'
'${location.toString().split('.').last}';
var directory = await Directory(derivedPath).create(recursive: true);
// make certain we have a random filename that doesn't already exist.
String path;
do {
var fileName = prefix + generateRandomFileName();
path = '${directory.path}/$fileName}';
} while (File(path).existsSync());
var tmpFile = File(path);
await tmpFile.create();
return tmpFile;
}