Flutter automatically update application when new version is available

前端 未结 5 1825
轮回少年
轮回少年 2021-02-05 17:14

How can I implement auto-updating of my application when a new version is released without using Google Play Store? I\'m using JSON to check the version.

5条回答
  •  梦谈多话
    2021-02-05 18:02

    My way of implementation is to use a variable and compare that variable from a database. It could be Firebase or any other. For this example, I will use Firebase realtime database.

    int version = 1;
    void checkLatestVersion(){
        
    //Here i am getting just the value of the latest version stored on firebase.    
    databaseReference.child("version").child("latestRealase").once().then((snapshot){
          if(snapshot.value != null){
              int versionNumberFromDatabase = int.parse(snapshot.value));
              if(versionNumberFromDatabase>version){
                 print("the app needs to be updated");
                 //HERE you can create a dialog to display and force users to update
              }else{
                 print("The app doesn't to be need updated ");
              }
          }
         });
     }
    

    The above example will work for both Android and iOS, but there is a package that will let you update your app from the app itself. Check the documentation.

    in_app_update 1.1.7

    This will enables In-App Updates on Android using the official Android APIs.

提交回复
热议问题