added persisted app settings
Some checks failed
Flutter APK Build / Build Flutter APK (pull_request) Has been cancelled

This commit is contained in:
2026-01-23 18:03:46 +01:00
parent cad43c7664
commit 83bfdf322b
5 changed files with 143 additions and 32 deletions

View File

@@ -14,21 +14,10 @@ class JsonFileService {
required List<Bookmark> bookmarks,
}) async {
try {
final dir = await _directoryPath;
final dir = await selectDirectoryPath();
if (dir.isEmpty) return false;
final data = {
'collections': collections.map((c) => c.toJson()).toList(),
'bookmarks': bookmarks.map((b) => b.toJson()).toList(),
};
final json = jsonEncode(data).codeUnits;
final file = XFile.fromData(
Uint8List.fromList(json),
mimeType: 'application/json',
name: constants.jsonFileName,
);
file.saveTo('$dir/${constants.jsonFileName}');
saveDataToFile(collections, bookmarks, dir);
} catch (e) {
return false;
}
@@ -65,7 +54,31 @@ class JsonFileService {
}
}
static Future<String> get _directoryPath async {
static Future<bool> saveDataToFile(
List<Collection> collections,
List<Bookmark> bookmarks,
String directory,
) async {
try {
final data = jsonEncode({
'collections': collections.map((c) => c.toJson()).toList(),
'bookmarks': bookmarks.map((b) => b.toJson()).toList(),
}).codeUnits;
final file = XFile.fromData(
Uint8List.fromList(data),
mimeType: 'application/json',
name: constants.jsonFileName,
);
file.saveTo('$directory/${constants.jsonFileName}');
} catch (e) {
return false;
}
return true;
}
static Future<String> selectDirectoryPath() async {
if (Platform.isAndroid) {
return await getDirectoryPath(
initialDirectory: constants.defaultAndroidExportDirectory,