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.
Maybe this help you
Backend backend = Backend.instance();
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String packageName = packageInfo.packageName;
Response r;
try {
r = await backend.io.get("https://play.google.com/store/apps/details?id=$packageName&hl=en");
if(r.statusCode == 200){
String data = r.data;
String pat1 = 'Current Version</div><span class="htlgb"><div class="IQ1z0d"><span class="htlgb">';
String pat2 = '</span>';
int p1 = data.indexOf(pat1) + pat1.length;
String f = data.substring(p1, data.length);
int p2 = f.indexOf(pat2);
String currentVersion = f.substring(0, p2);
return currentVersion;
}
return null;
} catch (e) {
errors = backend.interceptor.errors;
return null;
}
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.
Actually, in June 2020, we have more possibilities with Flutter. Among them:
1. Make updates inside the app. Display two kinds of notifications if the app has the new version.
Plugin - https://pub.dev/packages/in_app_update (works only on Android, iOS doesn't support such functionality)
2. When a newer app version is available in the app store, a simple alert prompt widget or card is displayed.
Works Android & iOS. Plugin - https://pub.dev/packages/upgrader
3. Use Firebase in-app messaging. It gives flexibility in the messages and forms of notifications. - But a lot more boilerplate code and work. + But you can use it for other messages and notifications when your app is growing.
https://firebase.google.com/docs/in-app-messaging
4. Make it by yourself. Maybe even less code then in the case with Firebase messaging.
It's not possible without using the google play store if you want an automatic update
.
A plugin exists if you want to do it using the play store. in_app_update Which wraps the android in-app update functionality
Their official example on github
If you also want an iOS solution, then it's not possible. You could redirect the user to the AppStore. Some more info on the distribution methods available for apple apps.
There is this method which might work if you have an enterprise license.
Whereas if you have a server running, have an endpoint to query the latest versions and another endpoint that allows users to download the apk.
Use something like github releases if you don't have a server.
You can use https://pub.dev/packages/flutter_downloader and put the user to download the update (apk file) directly from your app