Flutter: Get the device OS version

Updated: February 6, 2023 By: Augustus Post a comment

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.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles