version property
Version?
get
version
The version its pubspec declares, or null when it declares none (or it can't be read).
Implementation
Version? get version {
try {
final pubspec = File('$rootPath/pubspec.yaml');
if (!pubspec.existsSync()) return null;
final v = RegExp(
r'^version:\s*([^\s#]+)',
multiLine: true,
).firstMatch(pubspec.readAsStringSync())?.group(1);
return v == null
? null
: Version.tryParse(v.replaceAll('"', '').replaceAll("'", ''));
} on FileSystemException {
return null;
}
}