Alternatively:
new File('path/to/file').create(recursive: true);
Or:
new File('path/to/file').create(recursive: true)
.then((File file) {
// Stuff to do after file has been created...
});
Recursive means that if the file or path doesn’t exist, then it will be created. See: https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-io.File#id_create
EDIT: This way new Directory doesn’t need to be called! You can also do this in a synchronous way if you so choose:
new File('path/to/file').createSync(recursive: true);