From ce32f99e89d30f3c0c2b18baeb1adac73a01cb1b Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 22 Sep 2023 14:03:27 +0300 Subject: [PATCH] Null safety --- lib/utils/formatting.dart | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/utils/formatting.dart b/lib/utils/formatting.dart index 9815cbec4..d04d4b4b2 100644 --- a/lib/utils/formatting.dart +++ b/lib/utils/formatting.dart @@ -88,12 +88,14 @@ String? formatNumber( bool zeroIsNull = false, bool roundToPrecision = true, }) { - if ((zeroIsNull || - formatNumberType == FormatNumberType.inputMoney || - formatNumberType == FormatNumberType.inputAmount) && - value == 0) { + if (zeroIsNull && value == 0) { return null; - } else if (value == null) { + } else if (value == null || + (value == 0 && + ([ + FormatNumberType.inputMoney, + FormatNumberType.inputAmount, + ].contains(formatNumberType)))) { return ''; } @@ -344,7 +346,8 @@ String formatDuration(Duration? duration, {bool showSeconds = true}) { } } -DateTime convertTimeOfDayToDateTime(TimeOfDay? timeOfDay, [DateTime? dateTime]) { +DateTime convertTimeOfDayToDateTime(TimeOfDay? timeOfDay, + [DateTime? dateTime]) { dateTime ??= DateTime.now(); return DateTime(dateTime.year, dateTime.month, dateTime.day, timeOfDay?.hour ?? 0, timeOfDay?.minute ?? 0) @@ -479,7 +482,8 @@ String cleanApiUrl(String? url) => (url ?? '') .replaceFirst(RegExp(r'/api/v1'), '') .replaceFirst(RegExp(r'/$'), ''); -String? formatCustomValue({String? value, String? field, required BuildContext context}) { +String? formatCustomValue( + {String? value, String? field, required BuildContext context}) { final localization = AppLocalization.of(context); final state = StoreProvider.of(context).state; final CompanyEntity company = state.company!;