updatePubspecFonts method
Implementation
Future<void> updatePubspecFonts(List<dynamic> fontList) async {
final file = File(p.join(projectDir, 'pubspec.yaml'));
if (!file.existsSync()) {
throw BuildException(
'pubspec.yaml not found when trying to update fonts.',
fix: 'Verify the Flutter project contains pubspec.yaml.',
);
}
try {
final content = await file.readAsString();
final editor = YamlEditor(content);
editor.update(['flutter', 'fonts'], fontList);
await file.writeAsString(editor.toString());
} catch (e, s) {
throw BuildException(
'Failed to write font configuration to pubspec.yaml',
fix: 'Verify the "flutter:" entry exists in pubspec.yaml.',
originalStackTrace: s,
);
}
}