getUserHomeDir static method

String getUserHomeDir()

Implementation

static String getUserHomeDir() {
  // macOS / Linux
  if (Platform.isMacOS || Platform.isLinux) {
    final home = Platform.environment['HOME'];
    if (home != null && home.isNotEmpty) return home;
  }

  // Windows
  if (Platform.isWindows) {
    final userProfile = Platform.environment['USERPROFILE'];
    if (userProfile != null && userProfile.isNotEmpty) return userProfile;

    // Compatibility
    final homeDrive = Platform.environment['HOMEDRIVE'];
    final homePath = Platform.environment['HOMEPATH'];
    if (homeDrive != null && homePath != null) {
      return '$homeDrive$homePath';
    }
  }
  throw UserHomeDirectoryNotFoundException();
}