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 | |
parent | c9acbf458ff90d37be76fa32aeb1a2591d87144f (diff) |
Updated code to dart analysis recommendations
Diffstat (limited to 'lib/util')
-rw-r--r-- | lib/util/file_handler.dart | 44 | ||||
-rw-r--r-- | lib/util/notifications.dart | 4 | ||||
-rw-r--r-- | lib/util/storage_handler.dart | 8 |
3 files changed, 28 insertions, 28 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 diff --git a/lib/util/notifications.dart b/lib/util/notifications.dart index c652600..533a97b 100644 --- a/lib/util/notifications.dart +++ b/lib/util/notifications.dart @@ -25,8 +25,8 @@ class Notifications { /// Launches the notification static Future<void> notify(String title, String description, String payload) async { - const NotificationDetails _platformChannelSpecifics = NotificationDetails(android: _androidSpecifics); + const NotificationDetails platformChannelSpecifics = NotificationDetails(android: _androidSpecifics); - await flutterLocalNotificationsPlugin.show(0, title, description, _platformChannelSpecifics, payload: payload); + await flutterLocalNotificationsPlugin.show(0, title, description, platformChannelSpecifics, payload: payload); } } diff --git a/lib/util/storage_handler.dart b/lib/util/storage_handler.dart index fe27b93..d0897bd 100644 --- a/lib/util/storage_handler.dart +++ b/lib/util/storage_handler.dart @@ -4,17 +4,17 @@ import 'package:shared_preferences/shared_preferences.dart'; class StorageHandler { /// Stores the given `data` as a string with the `key`. static Future<String> store(String key, String data) async { - final _prefs = await SharedPreferences.getInstance(); + final prefs = await SharedPreferences.getInstance(); - _prefs.setString(key, data); + prefs.setString(key, data); return data; } /// Fetches the string related to the given `key`. static Future<String?> fetch(String key) async { - final _prefs = await SharedPreferences.getInstance(); + final prefs = await SharedPreferences.getInstance(); - return _prefs.getString(key); + return prefs.getString(key); } } |