getUserDir static method
获取用户目录
envName 其他环境变量名称
Implementation
static String getUserDir({
String? envName,
}) {
/// 读取环境变量,获取用户目录
String? p;
if (envName != null) {
p = Platform.environment[envName];
}
if (p == null) {
if (Platform.isWindows) {
p = Platform.environment['USERPROFILE'];
} else if (Platform.isMacOS || Platform.isLinux) {
p = Platform.environment['HOME'];
} else {
throw Exception('其他平台暂未支持');
}
}
if (p is! String) {
throw Exception('无法获取用户目录');
}
return p;
}