Kinda Code
Home/Flutter/Flutter: Get the device OS version

Flutter: Get the device OS version

Last updated: February 06, 2023

To get the device operating system version that your Flutter app is running on, just import dart:io and use Platform.operatingSystemVersion. No third-party package or installation is required.

A Quick Example

import 'dart:io';

void main() {
  // Detect the OS 
  print(Platform.operatingSystem);
  
  // The OS version
  print(Platform.operatingSystemVersion);
}

A Complete Example

Complete code in main.dart:

import 'package:flutter/material.dart';
import 'dart:io';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      // Remove the debug banner
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Kindacode.com'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(30),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // Display the platform
            Text(
              'Platform: ${Platform.operatingSystem}',
              style: const TextStyle(fontSize: 25),
            ),

            // Display the version
            Text(
              'Version: ${Platform.operatingSystemVersion}',
              style: const TextStyle(fontSize: 25),
            )
          ],
        ),
      ),
    );
  }
}

When running the code with your iOS simulator and Android emulator, you will get something like this (the platforms should be iOS and Android, but the versions may be different):

That’s it. Have a nice day. Further reading:

You can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.