getCurrentPackageName static method
Gets the current package name from pubspec.yaml
Implementation
static String? getCurrentPackageName() {
try {
final pubspecFile = File('pubspec.yaml');
if (pubspecFile.existsSync()) {
final content = pubspecFile.readAsStringSync();
final lines = content.split('\n');
for (final line in lines) {
if (line.trim().startsWith('name:')) {
final packageName = line.split(':')[1].trim();
return packageName.replaceAll(RegExp(r'["' + "']"), '');
}
}
}
} catch (e) {
// Return null if we can't determine package name
}
return null;
}