import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:path/path.dart' as path; import 'package:path_provider/path_provider.dart'; class Paths { static Future dataDirectory() async { switch (defaultTargetPlatform) { case TargetPlatform.linux: final home = Platform.environment['HOME']; if (home == null) return path.dirname(Platform.resolvedExecutable); if (await Directory(path.join(home, '.local', 'share')).exists()) { final target = await Directory(path.join(home, '.local', 'share', 'freezer')) .create(); return target.path; } return path.dirname(Platform.resolvedExecutable); case TargetPlatform.windows: final String? localAppData = Platform.environment['LOCALAPPDATA']; if (localAppData != null) { final target = await Directory(path.join(localAppData, 'Freezer')).create(); return target.path; } String? home = Platform.environment['USERPROFILE']; if (home == null) { final drive = Platform.environment['HOMEDRIVE']; final homepath = Platform.environment['HOMEPATH']; if (drive == null || homepath == null) { return path.dirname(Platform.resolvedExecutable); } home = drive + homepath; } final target = await Directory(path.join(home, 'AppData', 'Local', 'Freezer')).create(); return target.path; default: return (await getApplicationDocumentsDirectory()).path; } } static Future cacheDir() async { if (Platform.isLinux || Platform.isWindows) { final dataDir = await dataDirectory(); final target = await Directory(path.join(dataDir, 'cache')).create(); return target.path; } return (await getTemporaryDirectory()).path; } }