getDependencies method
Retrieves all dependencies listed in the pubspec.yaml
file.
This method reads and parses the pubspec.yaml
file, extracting:
- Regular dependencies (found under the
dependencies
key) - Development dependencies (found under the
dev_dependencies
key)
Returns a Set containing the names of all dependencies.
Throws an Exception if the pubspec.yaml
file is not found.
Implementation
Future<Set<String>> getDependencies() async {
final pubspecFile = File(filePath);
if (!pubspecFile.existsSync()) {
throw Exception('❌ Error: The file "$filePath" was not found!');
}
final content = pubspecFile.readAsStringSync();
final yamlMap = loadYaml(content) as Map;
final dependencies =
(yamlMap['dependencies'] as Map?)?.keys.toSet() ?? <String>{};
final devDependencies =
(yamlMap['dev_dependencies'] as Map?)?.keys.toSet() ?? <String>{};
return {...dependencies, ...devDependencies};
}