Closed hasanmhallak closed 7 months ago
There is a new version https://pub.dev/packages/upgrader/versions/9.0.0-alpha.1 that is in test and provides a way to handle this. Look at the examples included with the package.
hey @larryaasen I've just checked out the new version and I've found that you add a way to customize the alert/card, but still there is no access to the installed version or the store version. As I mentioned this issue it's important to have access to installedVersion
and storeVersion
so we can dynamically decide whether we want to force an update or not.
@hasanmhallak You should try this:
final upgrader = MyUpgrader(debugLogging: true);
...
UpgradeAlert(upgrader: upgrader);
...
class MyUpgrader extends Upgrader {
MyUpgrader({super.debugLogging});
@override
bool isUpdateAvailable() {
final appStoreVersion = currentAppStoreVersion();
final installedVersion = currentInstalledVersion();
print('appStoreVersion=$appStoreVersion');
print('installedVersion=$installedVersion');
return super.isUpdateAvailable();
}
}
In that example you subclass Upgrader
and override isUpdateAvailable
and you have access to the app store and installed versions. Does that work for you?
@larryaasen Thanks for the quick response.
Unfortunately this snippet won't solve the problem. The requirements I have is to check if the store has a major version release and force the user to update by hiding the ignore
and later
buttons.
But I've just looked at extending the Upgrader
class and found that I can override the showIgnore
& showLater
getters and still have access to currentAppStoreVersion()
& currentInstalledVersion()
so I guess this will do. I'll try to override them with our custom logic and see if this would solve the problem. Thank you.
@larryaasen Thanks for the quick response.
Unfortunately this snippet won't solve the problem. The requirements I have is to check if the store has a major version release and force the user to update by hiding the
ignore
andlater
buttons.But I've just looked at extending the
Upgrader
class and found that I can override theshowIgnore
&showLater
getters and still have access tocurrentAppStoreVersion()
¤tInstalledVersion()
so I guess this will do. I'll try to override them with our custom logic and see if this would solve the problem. Thank you.
I think you should be able to solve your custom upgrade logic the way you described. There are endless combinations of logic choices and they cannot all be added to this package, so having the ability to extend it works well.
This is not relevant any more as you can now override the Upgrader
class as below:
class AppUpgrader extends Upgrader {
@override
bool blocked() {
final installed =
int.tryParse(currentInstalledVersion?.split('.').first ?? '');
final store = int.tryParse(currentAppStoreVersion?.split('.').first ?? '');
if (installed == null || store == null) return false;
// block only if it's a major update.;
return store > installed;
}
}
So I'll close this.
closes #297