How to use Windows system variables in Flutter for Destop app?

Viewed 27

How to use Windows system environment variables in Flutter for Destop app (like %APPDATA%, %LOCALAPPDATA% and others)?

1 Answers

Just use the Platform.environment property to get the APPDATA and LOCALAPPDATA environment variables. Platform.environment is a Map<String, String?> where the key is the name of the environment variable and the value the current environment variable value.

Code example:

import 'dart:io';

void main(List<String> arguments) {
  final appData = Platform.environment['APPDATA'];
  final localAppData = Platform.environment['LOCALAPPDATA'];
  print('APPDATA = $appData');
  print('LOCALAPPDATA = $localAppData');
}

Output

APPDATA = C:\Users\Username\AppData\Roaming
LOCALAPPDATA = C:\Users\Username\AppData\Local
Related