Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.

Commit d6aadec

Browse files
author
eightgran
committed
Add documentation on BackupStorage
1 parent c68d7cb commit d6aadec

File tree

1 file changed

+13
-33
lines changed

1 file changed

+13
-33
lines changed

lib/controller/backup_storage.dart

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'dart:convert';
22
import 'dart:io';
33

44
import 'package:file_picker/file_picker.dart';
5-
import 'package:flutter/material.dart';
65
import 'package:lit_backup_service/data/data.dart';
76
import 'package:lit_backup_service/model/models.dart';
87
import 'package:permission_handler/permission_handler.dart';
@@ -47,6 +46,10 @@ class BackupStorage {
4746
/// https://support.google.com/googleplay/android-developer/answer/9214102#zippy=
4847
final bool useManageExternalStoragePermission;
4948

49+
/// The backup file's extension. Defaults to [EXTENSION_JSON].
50+
///
51+
/// File extensions allow custom file types and easier filtering when
52+
/// filtering for backup files.
5053
final String fileExtension;
5154

5255
/// The `installationID` is required in order to allow varying file names
@@ -86,8 +89,6 @@ class BackupStorage {
8689
" " +
8790
"backup.";
8891

89-
//String _currentFilePath = "";
90-
9192
/// Retrieves the currently selected `Media` directory on the local device's
9293
/// file system.
9394
///
@@ -123,9 +124,6 @@ class BackupStorage {
123124

124125
/// Creates the backup file.
125126
Future<File> _createLocalFile(String cachedPath) async {
126-
//final mediaPath = await _mediaLocation;
127-
//_createStorageDir(mediaPath);
128-
//final path = "$mediaPath$organizationName/$applicationName";
129127
return File(cachedPath);
130128
}
131129

@@ -214,6 +212,11 @@ class BackupStorage {
214212
}
215213
}
216214

215+
/// Shows the platform's native file explorer in order to pick a specific
216+
/// backup file.
217+
///
218+
/// If the requested [fileExtension] is not supported on the platform, no
219+
/// file extension filter will be applied.
217220
Future<BackupModel?> pickBackupFile({
218221
/// The serialization logic.
219222
///
@@ -224,15 +227,16 @@ class BackupStorage {
224227
FilePickerResult? result;
225228

226229
try {
230+
// Allow extension filtering
227231
result = await FilePicker.platform.pickFiles(
228232
type: FileType.custom,
229233
allowedExtensions: [fileExtension],
230234
);
231235
} catch (e) {
236+
// Use default
232237
result = await FilePicker.platform.pickFiles();
233238
print("File Extention '$fileExtension' not supported on this device.");
234239
print(e);
235-
debugPrintStack();
236240
}
237241

238242
if (result != null) {
@@ -241,6 +245,7 @@ class BackupStorage {
241245
print("Picked file cached at: " + pickedfile.path);
242246

243247
try {
248+
// Point to the cached backup file location.
244249
final file = await _createLocalFile(pickedfile.path);
245250
// Read the file
246251
final contents = await file.readAsString();
@@ -253,32 +258,7 @@ class BackupStorage {
253258
}
254259
} else {
255260
// User canceled the picker
256-
print("Selecting file aborted");
261+
print("Selecting file aborted.");
257262
}
258263
}
259-
260-
// /// Reads the backup from the selected location.
261-
// ///
262-
// /// Returns `null` if the backup has not been found or could not be
263-
// /// serialized.
264-
// Future<BackupModel?> readBackup({
265-
// /// The serialization logic.
266-
// ///
267-
// /// The logic will vary from Model class to Model class and must be
268-
// /// provided on each read-request.
269-
// required BackupModel Function(String) decode,
270-
// }) async {
271-
// print("Reading Backup...");
272-
// try {
273-
// final file = await _localPickedFile;
274-
// // Read the file
275-
// final contents = await file.readAsString();
276-
// print("Backup found on ${file.path}");
277-
// return decode(contents);
278-
// } catch (e) {
279-
// print(_notFoundErrorMessage);
280-
// print(e.toString());
281-
// return null;
282-
// }
283-
// }
284264
}

0 commit comments

Comments
 (0)