getProjectName method

String? getProjectName([
  1. String? pubspecPath
])

Get project name from pubspec.yaml

Implementation

String? getProjectName([String? pubspecPath]) {
  final File? pubspec = pubspecPath != null ? File(pubspecPath) : findPubspec();
  if (pubspec == null || !pubspec.existsSync()) return null;

  try {
    final String content = pubspec.readAsStringSync();
    final YamlMap? yaml = loadYaml(content) as YamlMap?;
    return yaml?['name']?.toString();
  } on Exception {
    return null;
  }
}