larryaasen / upgrader

A Flutter package for prompting users to upgrade when there is a newer version of the app in the store.
MIT License
531 stars 262 forks source link

Adding support for custom logic to enforce update. #297

Closed hasanmhallak closed 3 months ago

hasanmhallak commented 1 year ago

Introducing the ShouldBeBlocking Callback

Incorporating custom logic to determine whether an update should be enforced or not can greatly enhance the functionality of the upgrader package. The ShouldBeBlocking callback provides a valuable solution to this requirement.

Consider the following code snippet:

Upgrader(
  child: MyApp(),
  shouldBeBlocking: (installedVersion, storeVersion) {
    // Add your logic here to compare the installedVersion and storeVersion
    // Return true if the update should be enforced, false otherwise.
  },
);

This simple yet powerful approach enables you to enforce updates based on predefined conditions that are less likely to change over subsequent app updates. For instance, you can enforce major releases or crucial hotfix patches, while allowing users to make their own decision regarding minor updates.

The ShouldBeBlocking callback offers several advantages over alternatives like AppCast or minAppVersion. Configuring those alternatives manually can be time-consuming and may require rewriting significant parts of the code. Moreover, AppCast setup can pose challenges, especially for beginners, due to its complexities and intricate configuration. On the other hand, relying solely on the minimum app version specified in the app store description carries risks, as it disperses the enforcement logic outside of the app itself. It's worth noting that the individuals responsible for writing app store descriptions may not be the developers themselves, introducing potential discrepancies.

hasanmhallak commented 1 year ago

@larryaasen could you please review this suggestion and its associate PR so I can include it in my production?

larryaasen commented 3 months ago

@hasanmhallak Look at the latest version of this package with a latest customization options. I think it now meets your needs. If not, please open a new issue with your details.

hasanmhallak commented 3 months ago

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.

ChauCM commented 2 months ago

@hasanmhallak how do you do if I want to show only when minor update or major? for example: 1.1.1 -> 1.1.2, don't show upgrader 1.1.4 -> 1.2.1 show upgrader 1.10.1 -> 2.0.0 sho upgrader