addNew static method

bool addNew(
  1. String key,
  2. String value
)

Add new key to the config file.

TODO: Eventually, this method should be moved to the Config class.

Implementation

static bool addNew(String key, String value) {
  try {
    if (configFile.existsSync()) {
      String data = configFile.readAsStringSync();
      Map<String, dynamic> map =
          json.decode(data.isEmpty ? '{}' : data) as Map<String, dynamic>;
      map.addAll(<String, dynamic>{key: value});
      configFile.writeAsStringSync(json.encode(map));
    } else {
      configFile.createSync(recursive: true);
      configFile.writeAsStringSync(json.encode(<String, String>{key: value}));
    }
    return true;
  } catch (e) {
    wtLog.error('Failed to save key. $e');
    rethrow;
  }
}