read static method

SdkSettings read({
  1. Map<String, String>? environment,
})

The user's settings; the defaults when the file is missing or can't be read (a broken file is not worth stopping a command for).

Implementation

static SdkSettings read({Map<String, String>? environment}) {
  final at = path(environment: environment);
  if (at == null) return const SdkSettings();
  try {
    final file = File(at);
    if (!file.existsSync()) return const SdkSettings();
    final json = JsonFields.parse(file.readAsStringSync());
    return SdkSettings(
      alwaysDownload: json.optString('download') == 'always',
      declined: json.strings('declined'),
      extra: {
        for (final k in json.keys)
          if (k != 'download' && k != 'declined') k: json.raw(k),
      },
    );
  } on JsonFormatException {
    return const SdkSettings();
  } on FormatException {
    return const SdkSettings();
  } on FileSystemException {
    return const SdkSettings();
  }
}