From 0570147b3104eb329207ff374541d9d6797fe427 Mon Sep 17 00:00:00 2001 From: davidpkj Date: Sat, 11 Mar 2023 17:54:46 +0100 Subject: Updated code to dart analysis recommendations --- lib/util/file_handler.dart | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'lib/util/file_handler.dart') 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 serializeFile(BuildContext context, Map 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> deserializeFileInformation(File file) async { - final Map _content = jsonDecode(await file.readAsString()); - Map _map = Map(); + final Map content = jsonDecode(await file.readAsString()); + Map 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> encodeDataAsMap(ExportType type, Map data) async { - Map _map = Map(); + Map 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); + map.addAll(data as Map); - return _map; + return map; } /// Decodes the given `map` into -- cgit v1.2.3