Null safety

This commit is contained in:
Hillel Coren 2023-09-22 14:03:27 +03:00
parent a88f96e1f1
commit ce32f99e89
1 changed files with 11 additions and 7 deletions

View File

@ -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<AppState>(context).state;
final CompanyEntity company = state.company!;