save static method
Saves the flavor configuration to the YAML file.
Implementation
static void save(FlavorConfig config) {
final json = config.toJson();
// Values live in .env files — don't persist them in the YAML.
json.remove('values');
final file = File(_configPath);
String existingContent = '';
if (file.existsSync()) {
existingContent = file.readAsStringSync();
}
// We use YamlEditor to cleanly generate or update the YAML
final editor = YamlEditor(existingContent);
try {
editor.update([], json);
} catch (e) {
// If update fails on root, recreate
final freshEditor = YamlEditor('');
freshEditor.update([], json);
file.writeAsStringSync(freshEditor.toString());
return;
}
file.writeAsStringSync(editor.toString());
}