check null safety

This commit is contained in:
tzw
2021-09-10 14:27:38 +06:30
parent a144c945b6
commit 7670779b03
57 changed files with 620 additions and 626 deletions

View File

@@ -10,15 +10,15 @@ import 'package:fcs/domain/entities/rate.dart';
import 'package:fcs/domain/entities/shipment.dart';
class Invoice {
String id;
String invoiceNumber;
DateTime invoiceDate;
String fcsShipmentID;
String userID;
String fcsID;
String userName;
String phoneNumber;
String status;
String? id;
String? invoiceNumber;
DateTime? invoiceDate;
String? fcsShipmentID;
String? userID;
String? fcsID;
String? userName;
String? phoneNumber;
String? status;
double handlingFee;
double deliveryFee;
@@ -30,9 +30,9 @@ class Invoice {
List<CargoType> cargoTypes;
List<Shipment> shipments;
List<Payment> payments;
Discount discount;
PaymentMethod paymentMethod;
String invoiceURL;
Discount? discount;
PaymentMethod? paymentMethod;
String? invoiceURL;
List<CargoType> getCargoTypes(Rate rate) {
if (cargoTypes != null) return cargoTypes;
@@ -40,7 +40,7 @@ class Invoice {
List<CargoType> _cargoTypes = [];
double totalCalWeight = 0;
cartons.forEach((carton) {
if (carton.isChecked) {
if (carton.isChecked ?? false) {
var _cartonsTypes =
carton.getCargoTypeForCalWeight(rate.volumetricRatio);
_cartonsTypes.forEach((ct) {
@@ -68,15 +68,15 @@ class Invoice {
double getTotal(Rate rate) {
List<CargoType> cargoTypes = getCargoTypes(rate);
var total = cargoTypes.fold(0.0, (p, c) => c.calAmount + p);
double total = cargoTypes.fold(0.0, (p, c) => c.calAmount + p);
return total;
}
double get balance => (amount ?? 0) - (paidAmount ?? 0);
double get balance => amount - paidAmount;
double getNetAmount(Rate rate) {
List<CargoType> cargoTypes = getCargoTypes(rate);
var total = cargoTypes.fold(0.0, (p, c) => c.calAmount + p);
double total = cargoTypes.fold(0.0, (p, c) => c.calAmount + p);
total += getCustomFee();
total += getDeliveryFee();
total += getHandlingFee();
@@ -85,13 +85,13 @@ class Invoice {
}
double getHandlingFee() {
return shipments?.where((sh) => sh.isSelected ?? false)?.fold(0, (p, s) {
return p + (s?.handlingFee ?? 0) - (s?.paidHandlingFee ?? 0);
});
return shipments
.where((sh) => sh.isSelected)
.fold(0, (p, s) => p + (s.handlingFee - s.paidHandlingFee));
}
double getTotalBalance(Rate rate) {
return getNetAmount(rate) - (paidAmount ?? 0);
return getNetAmount(rate) - paidAmount;
}
double getCustomFee() {
@@ -102,7 +102,7 @@ class Invoice {
return deliveryFee == null ? 0 : deliveryFee;
}
double getDiscount() => discount == null ? 0 : discount.amount;
double getDiscount() => discount == null ? 0 : discount!.amount;
Invoice(
{this.id,
@@ -111,19 +111,19 @@ class Invoice {
this.fcsID,
this.userName,
this.phoneNumber,
this.amount,
this.paidAmount,
this.amount = 0,
this.paidAmount = 0,
this.discount,
this.status,
this.customDuties,
this.cartons,
this.cargoTypes,
this.handlingFee,
this.deliveryFee,
this.customDuties = const [],
this.cartons = const [],
this.cargoTypes = const [],
this.handlingFee = 0,
this.deliveryFee = 0,
this.fcsShipmentID,
this.shipments,
this.shipments = const [],
this.invoiceURL,
this.payments,
this.payments = const [],
this.paymentMethod});
factory Invoice.fromMap(Map<String, dynamic> map, String docID) {
@@ -153,7 +153,7 @@ class Invoice {
return Invoice(
id: docID,
invoiceNumber: map['invoice_number'],
invoiceDate: invd?.toDate(),
invoiceDate: invd.toDate(),
userName: map['user_name'],
fcsID: map['fcs_id'],
phoneNumber: map['phone_number'],
@@ -174,12 +174,12 @@ class Invoice {
Map<String, dynamic> toMap() {
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
List _customDuties = customDuties?.map((c) => c.toMap())?.toList();
List _cartons = cartons?.map((c) => c.toMap())?.toList() ?? [];
List _shipments = shipments?.map((s) => s.toMap())?.toList() ?? [];
List _customDuties = customDuties.map((c) => c.toMap()).toList();
List _cartons = cartons.map((c) => c.toMap()).toList();
List _shipments = shipments.map((s) => s.toMap()).toList();
return {
"id": id,
"invoice_date": invoiceDate?.toUtc()?.toIso8601String(),
"invoice_date": invoiceDate?.toUtc().toIso8601String(),
"user_id": userID,
"user_name": userName,
"invoice_number": invoiceNumber,