Auto-Update Application In Flutter
In pubspec.yaml file : add Packages,
Packages Name:
open_store: ^0.5.0
#new version update
new_version_plus: ^0.0.3
In Dart File: Write a Code,
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:new_version_plus/new_version_plus.dart';
import 'package:open_store/open_store.dart';
// Use this method for update app version or check version (main mathod)
//this method use for check app version then updated or Not updated
checkAppVersionUpdate(BuildContext context)async{
final newVersion=NewVersionPlus(
iOSId: 'com.example.app', // This is ios app package name
androidId: "com.example.app", // This is android app package name
);
final status= await newVersion.getVersionStatus();
print("store app_version:${status!.storeVersion}");
print(" local app_version:${status!.localVersion}");
print(" local app_version:${status!.canUpdate}");
_versionStatusCheck(newVersion,context);
}
//This method use for check version
_versionStatusCheck(NewVersionPlus newVersion,BuildContext context) async {
final status = await newVersion.getVersionStatus();
if(status!.canUpdate) {
updateAppVersionFromStore();
} else{
//You are use updated version
print("You are use updated new version");
}
}
//this method use for Go to App Store
updateAppVersionFromStore() async {
try{
await OpenStore.instance.open(
appStoreId: '1543803459', // This is app package name(appStoreId).
androidAppBundleId: 'com.example.app', // This is app package name(BundleId).
);
}catch(e){
print(e);
}
}
Comments
Post a Comment