checkForUpdate function
void
checkForUpdate()
Implementation
void checkForUpdate() async {
if (!CliConfig.updateIsCheckingToday()) {
if (!isDevVersion()) {
await PubDevApi.getLatestVersionFromPackage('sunac_flutter_cli')
.then((versionInPubDev) async {
await PubspecLock.getVersionCli(disableLog: true)
.then((versionInstalled) async {
if (versionInstalled == null) exit(2);
final v1 = Version.parse(versionInPubDev?.replaceAll('^', ''));
final v2 = Version.parse(versionInstalled);
final needsUpdate = v1.compareTo(v2);
// needs update.
if (needsUpdate == 1) {
LogService.info(Translation(
LocaleKeys.info_update_available.trArgs([versionInstalled]))
.toString());
printSunacFlutterCli();
final String? codeSample = LogService.code('sunac update');
LogService.info(
'${LocaleKeys.info_update_available2.trArgs([
versionInPubDev
])}${' $codeSample'}',
false,
true);
}
});
});
CliConfig.setUpdateCheckToday();
}
}
}