Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/emekalites/flutter_android_version

Get android version code and name
https://github.com/emekalites/flutter_android_version

Last synced: 4 days ago
JSON representation

Get android version code and name

Awesome Lists containing this project

README

        

[![Buy Me A Coffee](https://img.shields.io/badge/Donate-Buy%20Me%20A%20Coffee-yellow.svg)](https://www.buymeacoffee.com/emekaihedoro)

# androidversion

Get android version code and name.

## Description
Get the Android device Version Name, Release Code and Version Code.

## How to Use

Get Android Information:

```dart
Map androidInfo;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
androidInfo = await AndroidInfo.version;
//expected map {'name': 'P', 'code': 28, 'release': 9}
} on PlatformException {
androidInfo = 'Failed to get platform version.';
}
```

## Example

```dart
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:androidversion/androidversion.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State {
Map _info = {};

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

Future initPlatformState() async {
Map info;
try {
info = await AndroidInfo.version;
} on PlatformException {
info = {'error': 'Failed to get platform version.'};
}

if (!mounted) return;

setState(() => _info = info);
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('My App'),
),
body: Center(
child: Text('Running on: $_info\n'),
),
),
);
}
}

```