Skip to content

Repository files navigation

Flutter Community: get_version

Buy Me A CoffeeDonategithub pages

get_version

alt text

Online Demo: https://fluttercommunity.github.io/get_version/

Description

Get the Version Name, Version Code and App ID on iOS and Android.

Setup

Android

Go to build.gradle and update:

defaultConfig {
versionCode 1
versionName "1.0"
minSdkVersion 16
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

iOS

Already good to go.

How to Use

Get OS Version:

String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.try {
platformVersion =awaitGetVersion.platformVersion;
} onPlatformException {
platformVersion ='Failed to get platform version.';
}

Get Version Name:

String projectVersion;
// Platform messages may fail, so we use a try/catch PlatformException.try {
projectVersion =awaitGetVersion.projectVersion;
} onPlatformException {
projectVersion ='Failed to get project version.';
}

Get Version Code:

String projectCode;
// Platform messages may fail, so we use a try/catch PlatformException.try {
projectCode =awaitGetVersion.projectCode;
} onPlatformException {
projectCode ='Failed to get build number.';
}

Get App ID:

String projectAppID;
// Platform messages may fail, so we use a try/catch PlatformException.try {
projectAppID =awaitGetVersion.appID;
} onPlatformException {
projectAppID ='Failed to get app ID.';
}

Get App Name:

String projectName;
// Platform messages may fail, so we use a try/catch PlatformException.try {
projectName =awaitGetVersion.appName;
} onPlatformException {
projectName ='Failed to get app name.';
}

Example

import'package:flutter/material.dart';
import'package:flutter/services.dart';
import'package:get_version/get_version.dart';
voidmain() =>runApp(newMyApp());
classMyAppextendsStatefulWidget {
@override_MyAppStatecreateState() =>new_MyAppState();
}
class_MyAppStateextendsState<MyApp> {
String _platformVersion ='Unknown';
String _projectVersion ='';
String _projectCode ='';
String _projectAppID ='';
String _projectName ='';
@overrideinitState() {
super.initState();
initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.try {
platformVersion =awaitGetVersion.platformVersion;
} onPlatformException {
platformVersion ='Failed to get platform version.';
}
String projectVersion;
// Platform messages may fail, so we use a try/catch PlatformException.try {
projectVersion =awaitGetVersion.projectVersion;
} onPlatformException {
projectVersion ='Failed to get project version.';
}
String projectCode;
// Platform messages may fail, so we use a try/catch PlatformException.try {
projectCode =awaitGetVersion.projectCode;
} onPlatformException {
projectCode ='Failed to get build number.';
}
String projectAppID;
// Platform messages may fail, so we use a try/catch PlatformException.try {
projectAppID =awaitGetVersion.appID;
} onPlatformException {
projectAppID ='Failed to get app ID.';
}
String projectName;
// Platform messages may fail, so we use a try/catch PlatformException.try {
projectName =awaitGetVersion.appName;
} onPlatformException {
projectName ='Failed to get app name.';
}
// If the widget was removed from the tree while the asynchronous platform// message was in flight, we want to discard the reply rather than calling// setState to update our non-existent appearance.if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
_projectVersion = projectVersion;
_projectCode = projectCode;
_projectAppID = projectAppID;
_projectName = projectName;
});
}
@overrideWidgetbuild(BuildContext context) {
returnnewMaterialApp(
home:newScaffold(
appBar:newAppBar(
title:newText('Plugin example app'),
),
body:newSingleChildScrollView(
child:newListBody(
children:<Widget>[
newContainer(
height:10.0,
),
newListTile(
leading:newIcon(Icons.info),
title:constText('Name'),
subtitle:newText(_projectName),
),
newContainer(
height:10.0,
),
newListTile(
leading:newIcon(Icons.info),
title:constText('Running on'),
subtitle:newText(_platformVersion),
),
newDivider(
height:20.0,
),
newListTile(
leading:newIcon(Icons.info),
title:constText('Version Name'),
subtitle:newText(_projectVersion),
),
newDivider(
height:20.0,
),
newListTile(
leading:newIcon(Icons.info),
title:constText('Version Code'),
subtitle:newText(_projectCode),
),
newDivider(
height:20.0,
),
newListTile(
leading:newIcon(Icons.info),
title:constText('App ID'),
subtitle:newText(_projectAppID),
),
],
),
),
),
);
}
}

About

Get Version - Get the Version Name, Version Code, Platform and OS Version, and App ID on iOS and Android. Maintainer: @rodydavis

Topics

Resources

Stars

96 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages