VOOZH about

URL: https://dev.to/niamtokik/platform-identification-in-dartt-3b9i

⇱ Platform Identification in Dart - DEV Community


During the last weeks, I tried to learn a lot from Dart and Flutter, but even after a bit less than 1 month, I still don't know some basic stuff. When I was dealing with command line arguments parsing, I was thinking "how to get the goddamn program name". You know, the string you can simply have with argv[0] 1 in C or with the functions exported by the init module in Erlang. In Dart, you will require dart:io package and the Platform class.

Let write a small program to print out what kind of information this class store.

import 'dart:io' show Platform;

void main(List<String> arguments) {
 final info = systemInfo();
 for (final key in info.keys) {
 print("Platform.${key}: ${info[key]}");
 }
}

Map<String, dynamic> systemInfo() {
 return {
 "environment": Platform.environment,
 "executable": Platform.executable,
 "executableArguments": Platform.executableArguments,
 "isAndroid": Platform.isAndroid,
 "isFuchsia": Platform.isFuchsia,
 "isIOS": Platform.isIOS,
 "isLinux": Platform.isLinux,
 "isWindows": Platform.isWindows,
 "lineTerminator": Platform.lineTerminator,
 "localeName": Platform.localeName,
 "localHostname": Platform.localHostname,
 "numberOfProcessors": Platform.numberOfProcessors,
 "operatingSystem": Platform.operatingSystem,
 "operatingSystemVersion": Platform.operatingSystemVersion,
 "packageConfig": Platform.packageConfig,
 "pathSeparator": Platform.pathSeparator,
 "resolvedExecutable": Platform.resolvedExecutable,
 "script": Platform.script,
 "version": Platform.version
 };
}

The function systemInfo() returns a Map<String, dynamic> where the keys of the maps are simply a reference to the name of the Platform class attributes. Nothing complex there. When executed it will print the content of all attributes line by line.

Platform.environment: {
 SHELL: /bin/bash,
 ...
}
  • Platform.executable returns the name of the executable used to execute the application as a String, in our case, I am using dart run command (and then use the Dart VM);
Platform.executable: /.asdf/installs/flutter/3.41.7-stable/bin/cache/dart-sdk/bin/dart
  • Platform.executableArguments returns the arguments passed to the application as a List<String>, again, in our case, we are using the Dart VM, most of the arguments directly related to it;
Platform.executableArguments: [
 --resolved_executable_name=/.asdf/installs/flutter/3.41.7-stable/bin/cache/dart-sdk/bin/dart, 
 --executable_name=/.asdf/installs/flutter/3.41.7-stable/bin/cache/dart-sdk/bin/dart,
 --packages=.dart_tool/package_config.json
]
  • Platform.isLinux returns a Bool, it's true if it's a Linux system, else it's false. Other attributes like that are exposed to check easily what kind of systems is being used;
Platform.isLinux: true
Platform.localeName: en_US.UTF-8
Platform.localHostname: localhost
Platform.numberOfProcessors: 16
Platform.operatingSystem: linux
  • Platform.operatingSystemVersion returns the version of the system used as String, for Linux, it will be the version of the kernel, the same kind of string that could be returned by uname;
Platform.operatingSystemVersion: Linux 6.19.13+parrot7-amd64 #1 SMP PREEMPT_DYNAMIC Parrot 6.19.13-1parrot1 (2026-04-30)
Platform.resolvedExecutable: /.asdf/installs/flutter/3.41.7-stable/bin/cache/dart-sdk/bin/dart
  • Platform.script returns the script (Dart application) running in the current isolate (in our the default one) as String;
Platform.script: file:///tmp/dart/system_info/.dart_tool/pub/bin/system_info/system_info.dart-3.11.5.snapshot
Platform.version: 3.11.5 (stable) (Wed Apr 15 00:36:32 2026 -0700) on "linux_x64"

Sadly, one will not find a lot of resources about platform detection, at least, directly on Dart. Some posts can be found on the web regarding Flutter integration on different platform, but not so much when it comes to create a command line interface tool. Here a list containing other resources.

Happy hack and have fun!


Cover Image by GoRaivis Photography on Unsplash


  1. The function called at program startup is named main. The implementation declares no prototype for this function. It can be defined with no parameters or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared). [...] The value of argc shall be nonnegative. argv[argc] shall be a null pointer. From ANSI-C Specification