From 0716081d53ea7d6ceb56a7f9bba89cdd70d896df Mon Sep 17 00:00:00 2001 From: Koen Van Looveren Date: Wed, 6 Mar 2024 11:37:14 +0100 Subject: [PATCH] fix: added dateformatter & logger + updated dependencies --- lib/impaktfull_architecture.dart | 2 ++ lib/src/extension/list_extension.dart | 7 +++-- .../date_formatter/date_formatter_util.dart | 28 +++++++++++++++++ lib/src/util/logger/logger.dart | 30 +++++++++++++++++++ pubspec.yaml | 17 ++++++----- 5 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 lib/src/util/date_formatter/date_formatter_util.dart create mode 100644 lib/src/util/logger/logger.dart diff --git a/lib/impaktfull_architecture.dart b/lib/impaktfull_architecture.dart index d17946a..1ea055f 100644 --- a/lib/impaktfull_architecture.dart +++ b/lib/impaktfull_architecture.dart @@ -7,6 +7,8 @@ export 'src/model/data/error/localized_error.dart'; export 'src/model/data/error/network_error.dart'; export 'src/navigator/page_route/fade_in_page_route.dart'; export 'src/util/connectivity/connectivity.dart'; +export 'src/util/date_formatter/date_formatter_util.dart'; +export 'src/util/logger/logger.dart'; export 'src/util/storage/key_value/key_value_store.dart'; export 'src/util/storage/secure/secure_store.dart'; export 'src/util/storage/shared_prefs/shared_prefs_store.dart'; diff --git a/lib/src/extension/list_extension.dart b/lib/src/extension/list_extension.dart index e54e477..58512d5 100644 --- a/lib/src/extension/list_extension.dart +++ b/lib/src/extension/list_extension.dart @@ -16,6 +16,7 @@ extension ListExtension on List { Comparable? Function(T item) by, Comparable? Function(T item) by2, { bool ascending = true, + bool ascending2 = true, }) { sort((a, b) { final byA = by(a); @@ -30,9 +31,9 @@ extension ListExtension on List { final byA2 = by2(a); final byB2 = by2(b); if (byA2 == null && byB2 == null) return 0; - if (byA2 == null) return ascending ? -1 : 1; - if (byB2 == null) return ascending ? 1 : -1; - return _compareValues(byA2, byB2, ascending); + if (byA2 == null) return ascending2 ? -1 : 1; + if (byB2 == null) return ascending2 ? 1 : -1; + return _compareValues(byA2, byB2, ascending2); }); } } diff --git a/lib/src/util/date_formatter/date_formatter_util.dart b/lib/src/util/date_formatter/date_formatter_util.dart new file mode 100644 index 0000000..ca10198 --- /dev/null +++ b/lib/src/util/date_formatter/date_formatter_util.dart @@ -0,0 +1,28 @@ +import 'package:intl/intl.dart'; + +class DateFormatterUtil { + const DateFormatterUtil._(); + static String formatDate(DateTime date) { + final localDate = date.toLocal(); + final dateFormat = DateFormat('dd/MM/yyyy'); + return dateFormat.format(localDate); + } + + static String formatTime(DateTime date) { + final localDate = date.toLocal(); + final dateFormat = DateFormat('HH:mm'); + return dateFormat.format(localDate); + } + + static String formatDateTime(DateTime date) { + final localDate = date.toLocal(); + final dateFormat = DateFormat('dd/MM/yyyy HH:mm'); + return dateFormat.format(localDate); + } + + static String customFormat(DateTime date, String format) { + final localDate = date.toLocal(); + final dateFormat = DateFormat(format); + return dateFormat.format(localDate); + } +} diff --git a/lib/src/util/logger/logger.dart b/lib/src/util/logger/logger.dart new file mode 100644 index 0000000..4df236c --- /dev/null +++ b/lib/src/util/logger/logger.dart @@ -0,0 +1,30 @@ +import 'package:flutter/foundation.dart'; + +class ImpaktfullLogger { + const ImpaktfullLogger._(); + + static void log(Object message) { + if (kDebugMode) print(message); + } + + static void logError(String message, {Object? error, StackTrace? trace}) { + log(message); + if (error != null) { + log(error); + } + if (trace != null) { + log(trace); + } + } + + static void logFullError( + String message, { + required Object? error, + required StackTrace? trace, + }) => + logError(message, error: error, trace: trace); + + static void verbose(Object message) => log(message); + + static void debug(Object message) => log(message); +} diff --git a/pubspec.yaml b/pubspec.yaml index a2a4068..a91e2de 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,26 +7,27 @@ environment: flutter: ">=1.17.0" dependencies: connectivity_plus: ^5.0.2 - device_info_plus: ^9.1.1 + device_info_plus: ^9.1.2 flutter: sdk: flutter - dio: ^5.4.0 + dio: ^5.4.1 gap: ^3.0.1 - get_it: ^7.6.4 - impaktfull_ui: ^0.0.19 + get_it: ^7.6.7 + impaktfull_ui: ^0.0.31 injectable: ^2.3.2 + intl: ^0.18.1 flutter_secure_storage: ^9.0.0 - flutter_svg: ^2.0.9 + flutter_svg: ^2.0.10+1 path: ^1.8.3 - provider: ^6.1.1 + provider: ^6.1.2 package_info_plus: ^5.0.1 path_provider: ^2.1.2 shared_preferences: ^2.2.2 - snacky: ^0.0.5 + snacky: ^0.0.14 sprintf: ^7.0.0 synchronized: ^3.1.0+1 tuple: ^2.0.2 - url_launcher: ^6.2.2 + url_launcher: ^6.2.5 dev_dependencies: flutter_test: sdk: flutter