SettingsYaml.load constructor

SettingsYaml.load({
  1. required String pathToSettings,
})

Loads a settings file from the give pathToSettings.

If the settings file doesn't exist then it will be created when you call save.

The pathToSettings must point to a file (not a directory).

The directory component of pathToSettings maybe absolute or relative but the entire directory path must exist.

If the parent of pathToSettings doesn't exist then a SettingsYamlException will be thrown.

Implementation

factory SettingsYaml.load({required String pathToSettings}) {
  if (!exists(dirname(pathToSettings))) {
    throw SettingsYamlException(
        'The directory tree above ${truepath(pathToSettings)} does not exist.'
        ' Create the directory tree and try again.');
  }

  String? contents;
  if (exists(pathToSettings)) {
    contents = File(pathToSettings).readAsStringSync();
  }
  contents ??= '';

  return SettingsYaml.fromString(content: contents, filePath: pathToSettings);
}