null safety

This commit is contained in:
phyothandar
2021-09-10 17:14:59 +06:30
parent 4f7aa1b252
commit 2c95ec7600
21 changed files with 54 additions and 51 deletions

View File

@@ -28,7 +28,7 @@ class Invoice {
List<CustomDuty> customDuties; List<CustomDuty> customDuties;
List<Carton> cartons; List<Carton> cartons;
List<CargoType> cargoTypes; List<CargoType> cargoTypes;
List<Shipment> shipments; List<Shipment?>? shipments;
List<Payment> payments; List<Payment> payments;
Discount? discount; Discount? discount;
PaymentMethod? paymentMethod; PaymentMethod? paymentMethod;
@@ -85,9 +85,9 @@ class Invoice {
} }
double getHandlingFee() { double getHandlingFee() {
return shipments return shipments!
.where((sh) => sh.isSelected) .where((sh) => sh!.isSelected)
.fold(0, (p, s) => p + (s.handlingFee - s.paidHandlingFee)); .fold(0, (p, s) => p + (s!.handlingFee - s.paidHandlingFee));
} }
double getTotalBalance(Rate rate) { double getTotalBalance(Rate rate) {
@@ -176,7 +176,7 @@ class Invoice {
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList(); List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
List _customDuties = customDuties.map((c) => c.toMap()).toList(); List _customDuties = customDuties.map((c) => c.toMap()).toList();
List _cartons = cartons.map((c) => c.toMap()).toList(); List _cartons = cartons.map((c) => c.toMap()).toList();
List _shipments = shipments.map((s) => s.toMap()).toList(); List _shipments = shipments!.map((s) => s!.toMap()).toList();
return { return {
"id": id, "id": id,
"invoice_date": invoiceDate?.toUtc().toIso8601String(), "invoice_date": invoiceDate?.toUtc().toIso8601String(),

View File

@@ -36,7 +36,7 @@ class Package {
DeliveryAddress? deliveryAddress; DeliveryAddress? deliveryAddress;
//for packages in processing //for packages in processing
List<File> photoFiles; List<File?> photoFiles;
int get amount => rate != null && weight != null ? rate * weight : 0; int get amount => rate != null && weight != null ? rate * weight : 0;

View File

@@ -24,20 +24,24 @@ Future<Map?> getClaims({bool refreshIdToken = false}) async {
} }
// returns list of url // returns list of url
Future<List<String>> uploadFiles(String path, List<File> files, Future<List<String>> uploadFiles(String path, List<File?> files,
{String? fileName}) async { {String? fileName}) async {
List<Future<String>> fu = []; List<Future<String>> fu = [];
for (File f in files) { for (File? f in files) {
Future<String> u = uploadStorage(path, f); Future<String> u = uploadStorage(path, f);
fu.add(u); fu.add(u);
} }
return Future.wait(fu); return Future.wait(fu);
} }
Future<String> uploadStorage(String path, File file, {String? fileName}) async { Future<String> uploadStorage(String path, File? file,
{String? fileName}) async {
if (fileName == null) { if (fileName == null) {
fileName = Uuid().v4(); fileName = Uuid().v4();
} }
if (file == null) {
return Future.value('');
}
Reference ref = FirebaseStorage.instance.ref().child('$path/$fileName'); Reference ref = FirebaseStorage.instance.ref().child('$path/$fileName');
UploadTask uploadTask = ref.putFile(file); UploadTask uploadTask = ref.putFile(file);
await uploadTask.resume(); await uploadTask.resume();
@@ -57,10 +61,11 @@ Future<String> uploadStorage(String path, File file, {String? fileName}) async {
// return downloadUrl; // return downloadUrl;
} }
Future<void> deleteStorageFromUrls(List<String> urls) async { Future<void> deleteStorageFromUrls(List<String?> urls) async {
if (urls == null) return; if (urls == null) return;
for (int i = 0; i < urls.length; i++) { for (int i = 0; i < urls.length; i++) {
await deleteStorageFromUrl(urls[i]); if (urls[i] == null) return;
await deleteStorageFromUrl(urls[i]!);
} }
} }

View File

@@ -39,7 +39,7 @@ class _CargoTypeEditorState extends State<CargoTypeEditor> {
_loadDefalut() { _loadDefalut() {
ShipmentRateModel shipmentRateModel = ShipmentRateModel shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false); Provider.of<ShipmentRateModel>(context, listen: false);
_cargo = shipmentRateModel.rate.defaultCargoType?.clone(); _cargo = shipmentRateModel.rate.defaultCargoType.clone();
} }
@override @override

View File

@@ -171,7 +171,7 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
// } // }
try { try {
String barcode = await scanBarcode(); String? barcode = await scanBarcode();
if (barcode != null) { if (barcode != null) {
query = barcode; query = barcode;
showResults(context); showResults(context);

View File

@@ -103,10 +103,10 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
_loadShipments() async { _loadShipments() async {
ShipmentModel shipmentModel = ShipmentModel shipmentModel =
Provider.of<ShipmentModel>(context, listen: false); Provider.of<ShipmentModel>(context, listen: false);
List<Shipment> shipments = await shipmentModel.getShipmentWithHandlingFee( List<Shipment?>? shipments = await shipmentModel.getShipmentWithHandlingFee(
widget.fcsShipment!.id!, widget.customer!.id!); widget.fcsShipment!.id!, widget.customer!.id!);
shipments.forEach((s) { shipments!.forEach((s) {
s.isSelected = true; s!.isSelected = true;
}); });
setState(() { setState(() {
_invoice!.shipments = shipments; _invoice!.shipments = shipments;
@@ -380,8 +380,8 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
if (shipment == null) return; if (shipment == null) return;
shipment.isSelected = true; shipment.isSelected = true;
setState(() { setState(() {
_invoice!.shipments.remove(shipment); _invoice!.shipments!.remove(shipment);
_invoice!.shipments.add(shipment); _invoice!.shipments!.add(shipment);
}); });
} }
@@ -389,8 +389,8 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
if (shipment == null) return; if (shipment == null) return;
shipment.isSelected = false; shipment.isSelected = false;
setState(() { setState(() {
_invoice!.shipments.remove(shipment); _invoice!.shipments!.remove(shipment);
_invoice!.shipments.add(shipment); _invoice!.shipments!.add(shipment);
}); });
} }
@@ -431,7 +431,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
invoice.handlingFee = _invoice!.getHandlingFee(); invoice.handlingFee = _invoice!.getHandlingFee();
invoice.cartons = _invoice!.cartons.where((c) => c.isChecked!).toList(); invoice.cartons = _invoice!.cartons.where((c) => c.isChecked!).toList();
invoice.shipments = invoice.shipments =
_invoice!.shipments.where((s) => s.isSelected).toList(); _invoice!.shipments!.where((s) => s!.isSelected).toList();
invoice.discount = _invoice!.discount; invoice.discount = _invoice!.discount;
invoice.deliveryFee = _invoice!.deliveryFee; invoice.deliveryFee = _invoice!.deliveryFee;

View File

@@ -9,7 +9,7 @@ typedef OnAdd(Shipment shipment);
typedef OnRemove(Shipment shipment); typedef OnRemove(Shipment shipment);
class InvoiceHandlingFeeList extends StatelessWidget { class InvoiceHandlingFeeList extends StatelessWidget {
final List<Shipment>? shipments; final List<Shipment?>? shipments;
final OnAdd? onAdd; final OnAdd? onAdd;
final OnRemove? onRemove; final OnRemove? onRemove;
@@ -72,7 +72,7 @@ class InvoiceHandlingFeeList extends StatelessWidget {
onSelectChanged: (value) => Navigator.pop(context, c), onSelectChanged: (value) => Navigator.pop(context, c),
cells: [ cells: [
MyDataCell(new Text( MyDataCell(new Text(
c.shipmentNumber!, c!.shipmentNumber!,
style: textStyle, style: textStyle,
)), )),
MyDataCell( MyDataCell(

View File

@@ -39,8 +39,8 @@ class _InvoiceInfoState extends State<InvoiceInfo> {
void initState() { void initState() {
super.initState(); super.initState();
_invoice = widget.invoice!; _invoice = widget.invoice!;
_invoice!.shipments.forEach((s) { _invoice!.shipments!.forEach((s) {
s.isSelected = true; s!.isSelected = true;
}); });
_loadCartons(); _loadCartons();
} }

View File

@@ -70,11 +70,11 @@ class InvoiceTable extends StatelessWidget {
"${c.calWeight.toStringAsFixed(2)} x ${c.calRate.toStringAsFixed(2)}", "${c.calWeight.toStringAsFixed(2)} x ${c.calRate.toStringAsFixed(2)}",
amount: "${c.calAmount.toStringAsFixed(2)}")); amount: "${c.calAmount.toStringAsFixed(2)}"));
}); });
invoice!.shipments.where((ss) => (ss.isSelected )).forEach((s) { invoice!.shipments!.where((ss) => (ss!.isSelected )).forEach((s) {
tableRows.add(InvoiceTableRow( tableRows.add(InvoiceTableRow(
data: s, data: s,
invoiceDataType: InvoiceDataType.HandlingFeeType, invoiceDataType: InvoiceDataType.HandlingFeeType,
desc: "Handling fee\n${s.shipmentNumber}", desc: "Handling fee\n${s!.shipmentNumber}",
rate: "", rate: "",
amount: "${s.handlingFee.toStringAsFixed(2)}")); amount: "${s.handlingFee.toStringAsFixed(2)}"));
}); });

View File

@@ -260,7 +260,7 @@ class PackageModel extends BaseModel {
} }
Future<void> createReceiving( Future<void> createReceiving(
User user, Package package, List<File> files) async { User user, Package package, List<File?> files) async {
if (user != null) { if (user != null) {
package.fcsID = user.fcsID; package.fcsID = user.fcsID;
} }
@@ -288,22 +288,21 @@ class PackageModel extends BaseModel {
} }
} }
Future<void> updateReceiving(User user, Package package, List<File> files, Future<void> updateReceiving(User user, Package package, List<File?> files,
List<String> deletedUrls) async { List<String?> deletedUrls) async {
if (user != null) { if (user != null) {
package.fcsID = user.fcsID; package.fcsID = user.fcsID;
} }
if (deletedUrls != null) { if (deletedUrls != null) {
for (String url in deletedUrls) { for (String? url in deletedUrls) {
package.photoUrls.remove(url); package.photoUrls.remove(url);
} }
} }
List<String> uploadedURL = []; List<String> uploadedURL = [];
if (files != null) { if (files != null) {
var count = (package.photoUrls?.length ?? 0) + var count =
files.length - (package.photoUrls.length) + files.length - (deletedUrls.length);
(deletedUrls?.length ?? 0);
if (count > uploadPhotoLimit) if (count > uploadPhotoLimit)
throw Exception("Exceed number of file upload"); throw Exception("Exceed number of file upload");
@@ -333,18 +332,17 @@ class PackageModel extends BaseModel {
} }
Future<void> updateProcessing( Future<void> updateProcessing(
Package package, List<File> files, List<String> deletedUrls) async { Package package, List<File?> files, List<String?> deletedUrls) async {
if (deletedUrls != null) { if (deletedUrls != null) {
for (String url in deletedUrls) { for (String? url in deletedUrls) {
package.photoUrls.remove(url); package.photoUrls.remove(url);
} }
} }
List<String> uploadedURL = []; List<String> uploadedURL = [];
if (files != null) { if (files != null) {
var count = (package.photoUrls?.length ?? 0) + var count =
files.length - (package.photoUrls.length) + files.length - (deletedUrls.length);
(deletedUrls?.length ?? 0);
if (count > uploadPhotoLimit) if (count > uploadPhotoLimit)
throw Exception("Exceed number of file upload"); throw Exception("Exceed number of file upload");

View File

@@ -164,7 +164,7 @@ class _TrackingIDPageState extends State<TrackingIDPage> {
// } // }
try { try {
String barcode = await scanBarcode(); String? barcode = await scanBarcode();
if (barcode != null) { if (barcode != null) {
setState(() { setState(() {
_transcationIDCtl.text = barcode; _transcationIDCtl.text = barcode;

View File

@@ -147,7 +147,7 @@ class PackageSearchDelegate extends SearchDelegate<Package> {
// Barcode bc = barcodes.firstWhere((element) => true); // Barcode bc = barcodes.firstWhere((element) => true);
// String barcode; // String barcode;
// if (bc != null) barcode = bc.rawValue; // if (bc != null) barcode = bc.rawValue;
String barcode = await scanBarcode(); String? barcode = await scanBarcode();
if (barcode != null) { if (barcode != null) {
query = barcode; query = barcode;
showResults(context); showResults(context);

View File

@@ -80,7 +80,7 @@ class _ProfileState extends State<Profile> {
); );
final phonenumberbox = DisplayText( final phonenumberbox = DisplayText(
text: mainModel.user!.phone ?? "", text: mainModel.user!.phone,
labelTextKey: "profile.phone", labelTextKey: "profile.phone",
iconData: Icons.phone, iconData: Icons.phone,
); );

View File

@@ -36,7 +36,7 @@ class _CustomEditorState extends State<CustomEditor> {
_productController.text = _custom.name??""; _productController.text = _custom.name??"";
_feeController.text = _custom.customDutyFee.toStringAsFixed(2); _feeController.text = _custom.customDutyFee.toStringAsFixed(2);
_shipmentRateController.text = _shipmentRateController.text =
_custom.rate == null ? "" : _custom.rate?.toStringAsFixed(2) ?? ''; _custom.rate == null ? "" : _custom.rate.toStringAsFixed(2);
} else { } else {
_isNew = true; _isNew = true;
} }

View File

@@ -86,7 +86,7 @@ class _CustomListState extends State<CustomList> {
custom.rate == null custom.rate == null
? "" ? ""
: "Shipment rate \$ " + : "Shipment rate \$ " +
custom.rate!.toStringAsFixed(2)), custom.rate.toStringAsFixed(2)),
), ),
); );
}), }),

View File

@@ -62,11 +62,11 @@ class _ShipmentRatesCalState extends State<ShipmentRatesCal> {
var amount = box.calAmount(rate); var amount = box.calAmount(rate);
var shipmentWeight = box.getShipmentWeight(rate.volumetricRatio); var shipmentWeight = box.getShipmentWeight(rate.volumetricRatio);
var effectiveWeight = var effectiveWeight =
_cargoType.weight! > shipmentWeight ? _cargoType.weight : shipmentWeight; _cargoType.weight > shipmentWeight ? _cargoType.weight : shipmentWeight;
setState(() { setState(() {
_deliveryFee = _deliveryFee =
effectiveWeight! > rate.freeDeliveryWeight ? 0 : rate.deliveryFee; effectiveWeight > rate.freeDeliveryWeight ? 0 : rate.deliveryFee;
_amount = amount == null ? 0 : amount + _deliveryFee; _amount = amount == null ? 0 : amount + _deliveryFee;
_shipmentWeight = shipmentWeight.toDouble(); _shipmentWeight = shipmentWeight.toDouble();
}); });

View File

@@ -212,7 +212,7 @@ class _ReceivingEditorState extends State<ReceivingEditor> {
// } // }
try { try {
String barcode = await scanBarcode(); String? barcode = await scanBarcode();
if (barcode != null) { if (barcode != null) {
setState(() { setState(() {
_trackingIDCtl.text = barcode; _trackingIDCtl.text = barcode;

View File

@@ -56,7 +56,7 @@ class _ShipmentAssignState extends State<ShipmentAssign> {
_selectedShipmentType = _shipment!.shipmentType; _selectedShipmentType = _shipment!.shipmentType;
_fromTimeEditingController.text = _shipment!.pickupTimeStart!; _fromTimeEditingController.text = _shipment!.pickupTimeStart!;
_toTimeEditingController.text = _shipment!.pickupTimeEnd!; _toTimeEditingController.text = _shipment!.pickupTimeEnd!;
_pickupDate.text = dateFormatter.format(_shipment!.pickupDate! ?? now); _pickupDate.text = dateFormatter.format(_shipment!.pickupDate ?? now);
_handlingFee.text = _shipment!.handlingFee != null _handlingFee.text = _shipment!.handlingFee != null
? _shipment!.handlingFee.toString() ? _shipment!.handlingFee.toString()
: "0"; : "0";

View File

@@ -37,7 +37,7 @@ class _ShipmentConfirmState extends State<ShipmentConfirm> {
super.initState(); super.initState();
_shipment = widget.shipment; _shipment = widget.shipment;
_handlingFee.text = _shipment!.handlingFee?.toString() ?? "0"; _handlingFee.text = _shipment!.handlingFee.toString();
} }
@override @override

View File

@@ -223,7 +223,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
iconData: MaterialCommunityIcons.worker); iconData: MaterialCommunityIcons.worker);
var handlingFeeBox = DisplayText( var handlingFeeBox = DisplayText(
labelTextKey: "shipment.handling.fee", labelTextKey: "shipment.handling.fee",
text: (_shipment!.handlingFee ?? 0).toString(), text: (_shipment!.handlingFee).toString(),
iconData: FontAwesome.truck); iconData: FontAwesome.truck);
final assignCompleteBtn = LocalButton( final assignCompleteBtn = LocalButton(

View File

@@ -80,7 +80,7 @@ class MultiImgController {
List<File?> get getUpdatedFile { List<File?> get getUpdatedFile {
List<File?> _addfiles = getAddedFile; List<File?> _addfiles = getAddedFile;
this.imageFiles!.addAll(_addfiles); this.imageFiles.addAll(_addfiles);
return this.imageFiles; return this.imageFiles;
} }