getPackageVersion function
Get package version at given dir.
Default to current dir. Returns null if the dir does not exists or is not a pub package.
Implementation
Future<Version?> getPackageVersion({String? dir}) async {
try {
dir ??= '.';
var versionText =
(loadYaml(await File(join(dir, 'pubspec.yaml')).readAsString())
as Map)['version']
.toString();
var version = Version.parse(versionText);
return version;
} catch (_) {
return null;
}
}