Skip to main content

Using package_info - pubspec.yaml - auto update flutter app

If you need to get the version code or the package name, use this package_info in your pubspec.yaml

package_info: 0.4.1

take the current version from https://pub.dev/packages/package_info

if you neeed to use it before starting the whole application set this in you main.dart and call it from the begining of the initState,

let's suppose you've got a mechanism to have control over your version code, and each time you deliver a new app version code you want your users are forced to update the app, so one of many solutions to do it would be doing and enpoint in your api which get you the current application version code which is going to be compared with the is taken from the installed mobile phone, if they math the app goes on, if they do not, then you force the user to be redirected to a view in which the user is forced to update the new app

  void getVersionCode() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String versionName = packageInfo.version;
String versionCode = packageInfo.buildNumber;
String packageName = packageInfo.packageName;


Response res = await get(urlServer + "/v1/applicationversion",
headers: {'Content-Type': 'application/json;charset=utf-8'});
final jsonResponse = jsonDecode(res.body);
if (versionCode == jsonResponse.toString()) {
if (mounted){
setState(() {
packageName = packageName;
checkingApplicationVersion = true;
});
}
}
}

@override
void initState() {
super.initState();

getVersionCode();

}

@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
return new Future(() => false);
},
child: checkingApplicationVersion
? getStandardView()
: ForcingUpdatingApp(packageName));
// child: Text("dada"));
}


in that way before just before getStandardView()  is rendered there is a boolean which is analyzed if it is true, it will render the standard the normal view, if it is false it will be redirected to force the user to update to the new version


now to redirect the user from the app to the pay store, you need to set up in the pubspec.yaml store_redirect in this the version is store_redirect: ^1.0.1
be sure about taking the stable one 

now to use it from code, just use

StoreRedirect.redirect(
androidAppId: "com.example.yourpackagename",
iOSAppId: "585027354");   

and that's it, so you can trigger it from a button ike this

RaisedButton(
onPressed: () {
StoreRedirect.redirect(
androidAppId: packageName,
iOSAppId: "585027354");
},
color: Colors.lightGreen[700],
child: const Text('ACTUALIZAR',
style: TextStyle(fontSize: 17, color: Colors.white)),
)

Comments

Popular posts from this blog

How to deploy a VueJS App using Nginx on Ubuntu

There are thousands of blogs and websites out there explaining how to do a hello world and how to start with VueJS, but in this little post, I’m just going to be explaining how to do deploy a VueJs app after you have run the command through the CLI npm run build . So when you run the command npm run build a dist folder is created and that folder’s got the essential .js files to run our app, when we want to run our app on an Nginx server by default the vue-router is not going to work well so that Nginx does not come ready to work by default with a VueJs app This is basically for a Linux Ubuntu distribution if you’ve got any other Linux distribution just pay attention where is going to be set the www/html folder and the Nginx settings so that this is useful for any Linux distribution  Install and configure nginx sudo apt install nginx Double check to make sure the nginx service is running with command service nginx status, then open your browser and enter ...

Nginx reverse proxy for ReactJS, Vuejs,Laravel and Django with or without Docker

Nginx is an important piece on the working chain apps so that it works as bridge between the end user and the application servers, to do that we will be using nginx as a reverse proxy to know more in deep about nginx reverse proxy go to https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/ let's suppose you have a domain name called yourdomainame.com Nginx - ReactJS/Vuejs each time you need to create a new domain name, set it on the path /etc/nginx/conf.d/ create a file with vim or nano or whatever you want, and give it the domain name .conf and set the settings on it, this is really useful when you start handling several domain names under the same server vim /etc/nginx/conf.d/ yourdomainame.com.conf server {         server_name   yourdomainame.com wwww.yourdomainame.com;         # Load configuration files for the default server block.         include /etc/nginx/default.d/ *.conf ;   ...

How to use an SSL certificate for both the API using SpringBoot and for the FontEnd using VueJS or ReactJS

In the previous post  https://springboot-vuejs-reactjs.blogspot.com/2019/07/how-to-secure-springboot-with-ssl-and.html , we were doing the steps to get and install a certificate SSL for an apache tomcat embedded using SpringBoot , and we learned we can have as many SpringBoot applications secured with SSL as we want on the same server using the same   .p12  /  PKCS #12 file, so now we are going to be reviewing about how we can use the same certificate for apache tomcat and for an Nginx server at the same time. we were working on the folder /root/SSL the last generated file was the  apitester.p12 a  PKCS #12  file to work with Nginx with need two files a .crt and .key file and as we started the process securing apache tomcat we do not have those files but we get them using a converter through this webpage: https://decoder.link/converter let's chose the option PKCS#12 TO PEM an let's download the  apitester.p12 from the remote serv...