updateYamlFile method
Edits the pubspec.yaml file to add custom assets and dependencies.
Implementation
Future<void> updateYamlFile() async {
final content = await fileHandler.readFromFile(filePath: _pubspecPath);
final doc = loadYaml(content!) as Map;
final yamlEditor = YamlEditor('')
..update([], doc)
..update([
'dependencies',
], {
'flutter': {
'sdk': 'flutter',
},
...bricksManager.depPackagesOfYaml,
})
..update([
'dev_dependencies',
], {
'flutter_test': {
'sdk': 'flutter',
},
...bricksManager.devDepPackgesOfyaml,
})
..update([
'flutter',
], {
'uses-material-design': true,
'assets': ['assets/', '.env.development', '.env.production'],
})
..update(
['flutter_gen'],
{
'output': 'lib/core/gen/',
'line_length': 80,
'integrations': {
'flutter_svg': true,
},
'assets': {
'exclude': ['.env.development', '.env.production'],
},
},
);
// write the new YAML file into a new file
await fileHandler.createFile(
filePath: _pubspecPath,
data: yamlEditor.toString(),
modeIfExist: FileMode.write,
);
}