As an alternative:
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 does not exist, it will be created. See: https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-io.File#id_create
EDIT: Thus, the new directory does not need to be called! You can also do this synchronously if you so decide:
new File('path/to/file').createSync(recursive: true);
source share