added persisted app settings
Some checks failed
Flutter APK Build / Build Flutter APK (pull_request) Has been cancelled
Some checks failed
Flutter APK Build / Build Flutter APK (pull_request) Has been cancelled
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user