[Android] Try write to external storage first

This commit is contained in:
2023-09-08 14:33:47 +08:00
parent d2f8af335f
commit 64ce9ddf5d
2 changed files with 24 additions and 0 deletions

View File

@@ -26,6 +26,29 @@ class LogsFile {
await dir.create(recursive: true);
}
_cachedLogDirectory = dir;
final d1 = _file(DateTime.now());
if (d1 == null) {
throw Exception("Failed to create log file.");
}
return;
}
} catch (e) {
// Do nothing
}
}
if (isAndroid) {
try {
final io.Directory? dir = await getExternalStorageDirectory();
if (dir != null) {
final d = fs.directory(path.join(dir.path, "logs"));
if (!(await d.exists())) {
await d.create(recursive: true);
}
_cachedLogDirectory = d;
final d2 = _file(DateTime.now());
if (d2 == null) {
throw Exception("Failed to create log file.");
}
return;
}
} catch (e) {

View File

@@ -4,3 +4,4 @@ import 'package:flutter/foundation.dart';
bool get isDesktop =>
!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS);
bool get isWindows => !kIsWeb && Platform.isWindows;
bool get isAndroid => !kIsWeb && Platform.isAndroid;