Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - How to check is the app has a new version?

Tags:

flutter

I create an app with Flutter. I need to force users to update the app when I upload a new version. I try this package, but I think that it doesn´t work. In the documentation, we can read that we can verify the version with this code.

Container(
     margin: EdgeInsets.fromLTRB(12.0, 0.0, 12.0, 0.0),
     child: UpgradeCard();
)

The problem is: I need to check the version in *'initState', not in Scaffold. So what is the right way to check the version on the app start?

like image 406
El Hombre Sin Nombre Avatar asked Sep 23 '19 07:09

El Hombre Sin Nombre


People also ask

How do I know if I have the latest version of an app?

Android Settings Open the Settings app on your Android device. Open the "Applications" and/or "Application Manager" section. Tap on your app to select it. The App Settings Panel has multiple options including App Version, Notifications, and Location.

How do I check my app version in Flutter?

In Flutter apps the version number is available in pubspec. yaml file.


Video Answer


3 Answers

I recommend trying out the Firebase Remote Config and update the minimum required version there. It's not a good practice to force update app on every update in the store. Also, some users can see the updated version in given store later than others. This is just how Google Play and AppStore work.

Thus, when you really need to force update the application you can increment the parameter on Firebase e.g. a day after update in the store.

Simple code to trigger the dialog can look as following:

Future<bool> checkUpdates() async {
    await remoteConfig.fetch();
    await remoteConfig.activateFetched();

    final requiredBuildNumber = remoteConfig.getInt(Platform.isAndroid
        ? 'requiredBuildNumberAndroid'
        : 'requiredBuildNumberIOS');

    final currentBuildNumber = int.parse(packageInfo.buildNumber);

    return currentBuildNumber < requiredBuildNumber;
  }

This requires package_info package to be added as well as firebase_remote_config.

To open the app in the store you need to use url_launcher package and just pass URL to your app.

like image 166
Dominik Roszkowski Avatar answered Oct 19 '22 18:10

Dominik Roszkowski


you can call https://itunes.apple.com/lookup?bundleId=$id or https://play.google.com/store/apps/details?id=$id to receive the newest app version available on the stores. i can recommend this package to do this: https://pub.dev/packages/new_version

like image 5
Adam Smaka Avatar answered Oct 19 '22 19:10

Adam Smaka


You can check your app version like

@override
void initState() {
super.initState();
Timer( 
    Duration(seconds: 3), // put your stuff here
        () => Navigator.of(context).pushReplacement(MaterialPageRoute(
        builder: (BuildContext context) => LoginScreen())));}

and presume one thing this code must be in spalsh screen or home screen and there you can check app version forcefully stop any app which is belonged old version

like image 2
Hardik Kumbhani Avatar answered Oct 19 '22 17:10

Hardik Kumbhani