null safety

This commit is contained in:
Phaung Phaung
2021-09-10 15:23:13 +06:30
parent 5c5e47b9ad
commit 376153e22f
14 changed files with 80 additions and 66 deletions

View File

@@ -49,16 +49,19 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
_isNew = widget.shipment == null;
if (widget.shipment != null) {
_shipment = widget.shipment!;
_shipmentNumberController.text = _shipment.shipmentNumber;
_cutoffDateController.text = dateFormatter.format(_shipment.cutoffDate);
_arrivalDateController.text = dateFormatter.format(_shipment.arrivalDate);
_shipmentNumberController.text = _shipment.shipmentNumber ?? "";
if(_shipment.cutoffDate != null)
_cutoffDateController.text = dateFormatter.format(_shipment.cutoffDate!);
if(_shipment.arrivalDate != null)
_arrivalDateController.text = dateFormatter.format(_shipment.arrivalDate!);
if(_shipment.departureDate != null)
_departureDateControler.text =
dateFormatter.format(_shipment.departureDate);
_statusController.text = _shipment.status;
dateFormatter.format(_shipment.departureDate!);
_statusController.text = _shipment.status ?? "";
_currentShipmentType = _shipment.shipType;
_consigneeController.text = _shipment.consignee;
_portController.text = _shipment.port;
_destinationController.text = _shipment.destination;
_consigneeController.text = _shipment.consignee ?? "";
_portController.text = _shipment.port ?? "";
_destinationController.text = _shipment.destination ?? "";
} else {
var mainModel = Provider.of<MainModel>(context, listen: false);
_currentShipmentType = mainModel.setting.shipmentTypes[0];

View File

@@ -48,17 +48,20 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
}
_load() {
_shipmentNumberController.text = _fcsShipment!.shipmentNumber;
_cutoffDateController.text = dateFormatter.format(_fcsShipment!.cutoffDate);
_shipmentNumberController.text = _fcsShipment!.shipmentNumber ?? "";
if(_fcsShipment!.cutoffDate != null)
_cutoffDateController.text = dateFormatter.format(_fcsShipment!.cutoffDate!);
if(_fcsShipment!.arrivalDate != null)
_arrivalDateController.text =
dateFormatter.format(_fcsShipment!.arrivalDate);
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;
_destinationController.text = _fcsShipment!.destination;
_statusController.text = _fcsShipment!.status;
dateFormatter.format(_fcsShipment!.departureDate!);
_shipmentTypeControler.text = _fcsShipment!.shipType ?? "";
_consigneeController.text = _fcsShipment!.consignee ?? "";
_portController.text = _fcsShipment!.port ?? "";
_destinationController.text = _fcsShipment!.destination ?? "";
_statusController.text = _fcsShipment!.status ?? "";
}
@override
@@ -182,6 +185,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
}
_edit() async {
var f;
bool? updated = await Navigator.push<bool>(
context,
CupertinoPageRoute(
@@ -189,7 +193,8 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
);
if (updated ?? false) {
var shipmentModel = Provider.of<FcsShipmentModel>(context, listen: false);
var f = await shipmentModel.getFcsShipment(_fcsShipment!.id);
if(_fcsShipment != null && _fcsShipment!.id != null )
f = await shipmentModel.getFcsShipment(_fcsShipment!.id!);
setState(() {
_fcsShipment = f;
});

View File

@@ -43,9 +43,7 @@ class FcsShipmentListRow extends StatelessWidget {
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
shipment!.shipmentNumber == null
? ''
: shipment!.shipmentNumber,
shipment?.shipmentNumber ?? '',
style: new TextStyle(
fontSize: 15.0, color: Colors.black),
),
@@ -53,7 +51,7 @@ class FcsShipmentListRow extends StatelessWidget {
Padding(
padding: const EdgeInsets.only(left: 10.0, top: 10),
child: new Text(
dateFormatter.format(shipment!.cutoffDate),
dateFormatter.format(shipment!.cutoffDate!),
style: new TextStyle(
fontSize: 15.0, color: Colors.grey),
),
@@ -67,7 +65,7 @@ class FcsShipmentListRow extends StatelessWidget {
),
Padding(
padding: const EdgeInsets.all(0),
child: getStatus(shipment!.status),
child: getStatus(shipment!.status ?? ''),
),
],
),