From 273c0389c600db07ae964aba2500c442f9c2debb Mon Sep 17 00:00:00 2001 From: Phaung Phaung Date: Mon, 13 Sep 2021 14:24:04 +0630 Subject: [PATCH] fcs shipment update --- lib/pages/fcs_shipment/fcs_shipment_info.dart | 36 ++++++++++--------- .../model/fcs_shipment_model.dart | 2 +- lib/pages/processing/package_editor.dart | 4 +-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/pages/fcs_shipment/fcs_shipment_info.dart b/lib/pages/fcs_shipment/fcs_shipment_info.dart index ffd7723..d3fa572 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_info.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_info.dart @@ -48,15 +48,16 @@ class _FcsShipmentInfoState extends State { } _load() { - _shipmentNumberController.text = _fcsShipment!.shipmentNumber ?? ""; - if(_fcsShipment!.cutoffDate != null) - _cutoffDateController.text = dateFormatter.format(_fcsShipment!.cutoffDate!); - if(_fcsShipment!.arrivalDate != null) - _arrivalDateController.text = - dateFormatter.format(_fcsShipment!.arrivalDate!); - if(_fcsShipment!.departureDate != null) - _departureDateControler.text = - dateFormatter.format(_fcsShipment!.departureDate!); + _shipmentNumberController.text = _fcsShipment?.shipmentNumber ?? ""; + if (_fcsShipment?.cutoffDate != null) + _cutoffDateController.text = + dateFormatter.format(_fcsShipment!.cutoffDate!); + if (_fcsShipment?.arrivalDate != null) + _arrivalDateController.text = + dateFormatter.format(_fcsShipment!.arrivalDate!); + if (_fcsShipment?.departureDate != null) + _departureDateControler.text = + dateFormatter.format(_fcsShipment!.departureDate!); _shipmentTypeControler.text = _fcsShipment!.shipType ?? ""; _consigneeController.text = _fcsShipment!.consignee ?? ""; _portController.text = _fcsShipment!.port ?? ""; @@ -169,7 +170,7 @@ class _FcsShipmentInfoState extends State { portBox, destinationBox, statusBox, - _fcsShipment!.status == fcs_shipment_confirmed_status + _fcsShipment?.status == fcs_shipment_confirmed_status ? shipBtn : Container(), SizedBox( @@ -185,7 +186,6 @@ class _FcsShipmentInfoState extends State { } _edit() async { - var f; bool? updated = await Navigator.push( context, CupertinoPageRoute( @@ -193,12 +193,14 @@ class _FcsShipmentInfoState extends State { ); if (updated ?? false) { var shipmentModel = Provider.of(context, listen: false); - if(_fcsShipment != null && _fcsShipment!.id != null ) - f = await shipmentModel.getFcsShipment(_fcsShipment!.id!); - setState(() { - _fcsShipment = f; - }); - _load(); + if (_fcsShipment != null && _fcsShipment!.id != null) { + FcsShipment? f = await shipmentModel.getFcsShipment(_fcsShipment!.id!); + if (f == null) return; + setState(() { + _fcsShipment = f; + }); + _load(); + } } } diff --git a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart index 30242db..3667a88 100644 --- a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart +++ b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart @@ -124,7 +124,7 @@ class FcsShipmentModel extends BaseModel { .collection("/$fcs_shipment_collection") .doc(id) .get(const GetOptions(source: Source.server)); - var fcs = FcsShipment.fromMap(snap.data as Map, snap.id); + var fcs = FcsShipment.fromMap(snap.data()!, snap.id); return fcs; } catch (e) { diff --git a/lib/pages/processing/package_editor.dart b/lib/pages/processing/package_editor.dart index 458e3dc..207f662 100644 --- a/lib/pages/processing/package_editor.dart +++ b/lib/pages/processing/package_editor.dart @@ -44,10 +44,10 @@ class _PackageEditorState extends State { void initState() { super.initState(); _package = Package(); - _loadPackageData(widget.package!.id!); + _loadPackageData(widget.package?.id!); } - _loadPackageData(String id) async { + _loadPackageData(String? id) async { if (id != null) { PackageModel packageModel = Provider.of(context, listen: false);