hasDependency method

bool hasDependency(
  1. String package
)

true when package is in dependencies or dev_dependencies of the app pubspec.yaml

Implementation

bool hasDependency(String package) {
  String section = '';
  for (String line in _file('pubspec.yaml').readAsLinesSync()) {
    if (line.isNotEmpty && !line.startsWith(' ') && !line.startsWith('#')) {
      section = line.split(':').first.trim();
    } else if ((section == 'dependencies' || section == 'dev_dependencies') &&
        RegExp('^\\s+$package\\s*:').hasMatch(line)) {
      return true;
    }
  }
  return false;
}