fetchSavedBridges static method
Fetch all of the bridges already saved to the user's device.
decrypter
When the bridge data is read from local storage, it is
decrypted. This parameter allows you to provide your own decryption
method. This will be used in addition to the default decryption method.
This will be performed after the default decryption method.
directory
The directory where the bridge data will be saved. If this is
not provided, the default directory will be used.
If the bridges are not saved to the default folder location, provide their
location with directory
.
Implementation
static Future<List<Bridge>> fetchSavedBridges({
String Function(String ciphertext)? decrypter,
Directory? directory,
}) async {
List<Bridge> bridges = [];
if (kIsWeb) {
// cookies instead of local storage (not yet implemented)
} else {
final Directory dir = directory ??
Directory(
await MyFileExplorerSDK.createPath(
localDir: LocalDir.appSupportDir,
subPath: Folders.bridgesSubPath,
),
);
/// Create the directory if it does not exist.
if (!dir.existsSync()) {
dir.createSync(recursive: true);
return [];
}
// Get the bridge files from the directory.
final List<FileSystemEntity> entities = await dir.list().toList();
final List<File> bridgeFiles = entities
.whereType<File>()
.where((file) =>
MyFileExplorerSDK.tryParseFileExt(file.path)?.toLowerCase() ==
".json")
.toList();
/// Parse the bridge files into [Bridge] objects.
for (File bridgeFile in bridgeFiles) {
String fileContents = LocalStorageRepo.decrypt(
bridgeFile.readAsStringSync(),
decrypter,
) ??
"";
Map<String, dynamic> bridgeJson = JsonTool.readJson(fileContents);
bridges.add(Bridge.fromJson(bridgeJson));
}
}
return bridges;
}