How to check the device OS version from Flutter?

DartFlutter

Dart Problem Overview


Platform.operatingSystem will tell you whether you're running on Android or iOS.

How can I check which version of the device OS am I running on?

Dart Solutions


Solution 1 - Dart

Add this plugin to your pubspec device_info

Human-readable way is

if (Platform.isAndroid) {
  var androidInfo = await DeviceInfoPlugin().androidInfo;
  var release = androidInfo.version.release;
  var sdkInt = androidInfo.version.sdkInt;
  var manufacturer = androidInfo.manufacturer;
  var model = androidInfo.model;
  print('Android $release (SDK $sdkInt), $manufacturer $model');
  // Android 9 (SDK 28), Xiaomi Redmi Note 7
}

if (Platform.isIOS) {
  var iosInfo = await DeviceInfoPlugin().iosInfo;
  var systemName = iosInfo.systemName;
  var version = iosInfo.systemVersion;
  var name = iosInfo.name;
  var model = iosInfo.model;
  print('$systemName $version, $name $model');
  // iOS 13.1, iPhone 11 Pro Max iPhone
}

Solution 2 - Dart

import 'dart:io' show Platform;

void main() {
  // Get the operating system as a string.
  String os = Platform.operatingSystem;
  // Or, use a predicate getter.
  if (Platform.isMacOS) {
    print('is a Mac');
  } else {
    print('is not a Mac');
  }
}

Dart SDK > dart:io > Platform

Here is the official article above, and if you want to check it is IOS or Andriod, you can use:

if (Platform.isIOS) {
  print('is a IOS');
} else if (Platform.isAndroid) {
  print('is a Andriod');
} else {
}

Solution 3 - Dart

You can use dart:io

import 'dart:io' show Platform;

String osVersion = Platform.operatingSystemVersion;

Solution 4 - Dart

You can use platform channels for this task. In native use os specific code to get version and resend it to flutter. Here is good example with battery level

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDogeLionView Question on Stackoverflow
Solution 1 - DartAiron TarkView Answer on Stackoverflow
Solution 2 - DartJulienView Answer on Stackoverflow
Solution 3 - Dartpankaj kumarView Answer on Stackoverflow
Solution 4 - DartGerman SaprykinView Answer on Stackoverflow