乐闻世界logo
搜索文章和话题

How to Check Device Operating System Version in Flutter?

2月7日 11:22

In Flutter, you can check the device's operating system version by using the Platform class from the dart:io library. Here are the specific steps and example code:

  1. Import the dart:io library:
dart
import 'dart:io';
  1. Use the operatingSystemVersion property of the Platform class to retrieve the operating system version:
dart
String osVersion = Platform.operatingSystemVersion;

This property returns a string containing the operating system version. You can leverage this approach to implement different logic or provide specific features tailored to varying operating system versions.

Example code:

dart
import 'dart:io'; void checkOSVersion() { String osVersion = Platform.operatingSystemVersion; print("Current operating system version: $osVersion"); } void main() { checkOSVersion(); }

This function outputs the device's operating system version to the console.

标签:Dart