SafePath constructor

SafePath(
  1. String _path
)

Create a safe path from _path. It will be created as a folder if it does not exist.

Implementation

SafePath(this._path) {
  // Check if path exists and see if it is a file or a folder
  Directory dir = Directory(_path);
  File file = File(_path);
  if (!dir.existsSync()) {
    if (file.existsSync()) {
      isFile = true;
    } else {
      // Create path
      dir.createSync(recursive: true);
    }
  }

  // Set path
  if (isFile) {
    _path = file.path;
  } else {
    _path = dir.path;
  }
}