cacheDir static method

String? cacheDir(
  1. String name, {
  2. Map<String, String>? environment,
})

A cache folder called name: %LOCALAPPDATA%\<name> on Windows, ~/Library/Caches/<name> on macOS, $XDG_CACHE_HOME/<name> (or ~/.cache/<name>) elsewhere. Null when the home folder can't be found.

Implementation

static String? cacheDir(String name, {Map<String, String>? environment}) {
  final env = environment ?? Platform.environment;
  String? base;
  if (Platform.isWindows) {
    base = _set(env['LOCALAPPDATA']) ?? _set(env['APPDATA']);
  } else if (Platform.isMacOS) {
    final home = _set(env['HOME']);
    base = home == null ? null : '$home/Library/Caches';
  } else {
    final home = _set(env['HOME']);
    base =
        _absolute(env['XDG_CACHE_HOME']) ??
        (home == null ? null : '$home/.cache');
  }
  return base == null ? null : '${_trimmed(base)}/$name';
}