diff options
author | davidpkj <davidpenkow1@gmail.com> | 2023-03-11 17:54:46 +0100 |
---|---|---|
committer | davidpkj <davidpenkow1@gmail.com> | 2023-03-11 17:54:46 +0100 |
commit | 0570147b3104eb329207ff374541d9d6797fe427 (patch) | |
tree | 41da77cffc72c8a8e9329c9dde0bff3a4c7f9ecc /lib/util/file_handler.dart | |
parent | c9acbf458ff90d37be76fa32aeb1a2591d87144f (diff) |
Updated code to dart analysis recommendations
Diffstat (limited to 'lib/util/file_handler.dart')
-rw-r--r-- | lib/util/file_handler.dart | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/lib/util/file_handler.dart b/lib/util/file_handler.dart index d6b909d..b230e35 100644 --- a/lib/util/file_handler.dart +++ b/lib/util/file_handler.dart @@ -27,13 +27,13 @@ class FileHandler { static Future<void> serializeFile(BuildContext context, Map<String, dynamic> data) async { if (await Permission.storage.request().isGranted) { try { - final _directory = await ExternalPath.getExternalStoragePublicDirectory(ExternalPath.DIRECTORY_DOWNLOADS); - final _file = File("$_directory/Export-${DateTime.now().toUtc().toString().split(" ")[0]}.kulinar"); + final directory = await ExternalPath.getExternalStoragePublicDirectory(ExternalPath.DIRECTORY_DOWNLOADS); + final file = File("$directory/Export-${DateTime.now().toUtc().toString().split(" ")[0]}.kulinar"); - await _file.writeAsString(jsonEncode(await encodeDataAsMap(ExportType.full, data))); + await file.writeAsString(jsonEncode(await encodeDataAsMap(ExportType.full, data))); ToastBar.showToastBar(context, AppLocalizations.of(context)!.exportSuccess, actionLabel: ""); - Notifications.notify(AppLocalizations.of(context)!.exportSuccess, AppLocalizations.of(context)!.tapHint, _file.path); + Notifications.notify(AppLocalizations.of(context)!.exportSuccess, AppLocalizations.of(context)!.tapHint, file.path); } catch (e) { debugPrint("$e"); ToastBar.showToastBar(context, AppLocalizations.of(context)!.exportError, actionLabel: ""); @@ -43,31 +43,31 @@ class FileHandler { /// Deserializes the given `file` into the returned Map. Sends a confirmation Toast to the given `context` afterwards. static Future deserializeFile(BuildContext context, File file) async { - final dynamic _content = jsonDecode(await file.readAsString()); + final dynamic content = jsonDecode(await file.readAsString()); - SettingsData.decode(_content["settings"]); - RecipeData.decode(_content["recipes"]); + SettingsData.decode(content["settings"]); + RecipeData.decode(content["recipes"]); ToastBar.showToastBar(context, AppLocalizations.of(context)!.importSuccess, actionLabel: ""); } /// Parses a given possible deserializable `file` for useful information and returns a map of it. static Future<Map<String, String>> deserializeFileInformation(File file) async { - final Map<dynamic, dynamic> _content = jsonDecode(await file.readAsString()); - Map<String, String> _map = Map<String, String>(); + final Map<dynamic, dynamic> content = jsonDecode(await file.readAsString()); + Map<String, String> map = {}; - _map["version"] = _content["version"]; - _map["type"] = _content["type"].split(".")[1]; - _map["size"] = "${await file.length()} Bytes"; + map["version"] = content["version"]; + map["type"] = content["type"].split(".")[1]; + map["size"] = "${await file.length()} Bytes"; - if (_content["type"] == ExportType.full.toString()) { - int a = jsonDecode(_content["recipes"]).length; - int b = jsonDecode(_content["settings"]).length; + if (content["type"] == ExportType.full.toString()) { + int a = jsonDecode(content["recipes"]).length; + int b = jsonDecode(content["settings"]).length; - _map["entries"] = (a + b).toString(); + map["entries"] = (a + b).toString(); } - return _map; + return map; } /// Opens the native file picker and returns the picked `.kulinar` file. @@ -90,14 +90,14 @@ class FileHandler { /// Encodes the given `data` together with some additional information into a serializable map. static Future<Map<String, String>> encodeDataAsMap(ExportType type, Map<String, dynamic> data) async { - Map<String, String> _map = Map<String, String>(); + Map<String, String> map = {}; - _map["version"] = cVersion; - _map["type"] = type.toString(); + map["version"] = cVersion; + map["type"] = type.toString(); // TODO: IMPLEMENT: Base64 Images and image count on export - _map.addAll(data as Map<String, String>); + map.addAll(data as Map<String, String>); - return _map; + return map; } /// Decodes the given `map` into |