getModuleName function

String getModuleName()

Reads the name: field from the project's pubspec.yaml. Returns an empty string if the file is missing or has no name: field.

Implementation

String getModuleName() {
  final pubspec = File('pubspec.yaml');
  if (pubspec.existsSync()) {
    final lines = pubspec.readAsLinesSync();
    for (var line in lines) {
      if (line.startsWith('name:')) {
        return line.split(':')[1].trim();
      }
    }
  }
  return '';
}