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.environmentreturns the environment in aMap<String, String>;
Platform.environment: {
SHELL: /bin/bash,
...
}
-
Platform.executablereturns the name of the executable used to execute the application as aString, in our case, I am usingdart runcommand (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.isLinuxreturns aBool, 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.localeNamereturns the locale environment asString, useful for the localization;
Platform.localeName: en_US.UTF-8
-
Platform.localHostnamereturns the name of the host (defined in/etc/hostsor in/etc/hostname) asString;
Platform.localHostname: localhost
-
Platform.numberOfProcessorsreturns the number of available CPU asint, no distinctions between a real CPU or a core;
Platform.numberOfProcessors: 16
-
Platform.operatingSystemreturns the code name of the system as aString;
Platform.operatingSystem: linux
-
Platform.operatingSystemVersionreturns the version of the system used asString, for Linux, it will be the version of the kernel, the same kind of string that could be returned byuname;
Platform.operatingSystemVersion: Linux 6.19.13+parrot7-amd64 #1 SMP PREEMPT_DYNAMIC Parrot 6.19.13-1parrot1 (2026-04-30)
-
Platform.resolvedExecutablereturns the full path of the executable as aString;
Platform.resolvedExecutable: /.asdf/installs/flutter/3.41.7-stable/bin/cache/dart-sdk/bin/dart
-
Platform.scriptreturns the script (Dart application) running in the current isolate (in our the default one) asString;
Platform.script: file:///tmp/dart/system_info/.dart_tool/pub/bin/system_info/system_info.dart-3.11.5.snapshot
-
Platform.versionreturns the Dart version used for this application asString
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.
Platformclass API Documentation fromdart:iomodule;Flutter: Understanding dart:io Platform, defaultTargetPlatform, and kIsWeb (and When to Use Each) on Medium
How do you detect the host platform from Dart code? on Medium
Dart Platform on ZetCode
Happy hack and have fun!
Cover Image by GoRaivis Photography on Unsplash
-
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
argcandargv, though any names may be used, as they are local to the function in which they are declared). [...] The value ofargcshall be nonnegative.argv[argc]shall be a null pointer. From ANSI-C Specification ↩
Top comments (0)