diff --git a/lib/domain/entities/shipment.dart b/lib/domain/entities/shipment.dart index 2d4cabc..d1b31d6 100644 --- a/lib/domain/entities/shipment.dart +++ b/lib/domain/entities/shipment.dart @@ -52,7 +52,7 @@ class Shipment { this.pickupDate, this.isCourier = false, this.radioIndex = 1, - required this.pickupAddress, + this.pickupAddress, this.pickupUserID, this.pickupUserName, this.pickupUserPhoneNumber, diff --git a/lib/pages/carton/carton_editor.dart b/lib/pages/carton/carton_editor.dart index e83d6b1..4cd1c36 100644 --- a/lib/pages/carton/carton_editor.dart +++ b/lib/pages/carton/carton_editor.dart @@ -10,7 +10,6 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/carton/carton_package_table.dart'; import 'package:fcs/pages/carton_search/carton_search.dart'; import 'package:fcs/pages/carton_size/carton_size_list.dart'; -import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart'; import 'package:fcs/pages/fcs_shipment/model/fcs_shipment_model.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:fcs/pages/package/model/package_model.dart'; @@ -40,8 +39,8 @@ import 'package_carton_editor.dart'; import 'widgets.dart'; class CartonEditor extends StatefulWidget { - final Carton? box; - CartonEditor({this.box}); + final Carton? carton; + CartonEditor({this.carton}); @override _CartonEditorState createState() => _CartonEditorState(); @@ -63,7 +62,7 @@ class _CartonEditorState extends State { double volumetricRatio = 0; double shipmentWeight = 0; FcsShipment? _fcsShipment; - List? _fcsShipments; + List _fcsShipments = []; List _cartons = []; CartonSize? selectedCatonSize; @@ -90,8 +89,8 @@ class _CartonEditorState extends State { _widthController.addListener(_calShipmentWeight); _heightController.addListener(_calShipmentWeight); - if (widget.box != null) { - _carton = widget.box; + if (widget.carton != null) { + _carton = widget.carton; _deliveryAddress = _carton!.deliveryAddress; _widthController.text = _carton!.width.toString(); _heightController.text = _carton!.height.toString(); @@ -138,11 +137,13 @@ class _CartonEditorState extends State { FcsShipmentModel fcsShipmentModel = Provider.of(context, listen: false); var fcsShipments = await fcsShipmentModel.getActiveFcsShipments(); - var fcsShipment = - fcsShipments.firstWhere((e) => e.id == _carton!.fcsShipmentID); + + // var fcsShipment = + // fcsShipments.firstWhere((e) => e.id == _carton?.fcsShipmentID); + setState(() { _fcsShipments = fcsShipments; - _fcsShipment = fcsShipment; + // _fcsShipment = fcsShipment; }); } @@ -195,9 +196,9 @@ class _CartonEditorState extends State { // } _calShipmentWeight() { - double l = double.parse(_lengthController.text); - double w = double.parse(_widthController.text); - double h = double.parse(_heightController.text); + double l = double.tryParse(_lengthController.text) ?? 0; + double w = double.tryParse(_widthController.text) ?? 0; + double h = double.tryParse(_heightController.text) ?? 0; setState(() { shipmentWeight = l * w * h / volumetricRatio; }); @@ -248,8 +249,8 @@ class _CartonEditorState extends State { labelKey: "shipment.pack.fcs.shipment", iconData: Ionicons.ios_airplane, display: (u) => u.shipmentNumber, - selectedValue: _fcsShipment!, - values: _fcsShipments!, + selectedValue: _fcsShipment, + values: _fcsShipments, )); final fcsIDBox = Container( diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index 68358c3..db67495 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -144,9 +144,9 @@ class _CartonInfoState extends State { } _calShipmentWeight() { - double l = double.parse(_lengthController.text); - double w = double.parse(_widthController.text); - double h = double.parse(_heightController.text); + double l = double.tryParse(_lengthController.text) ?? 0; + double w = double.tryParse(_widthController.text) ?? 0; + double h = double.tryParse(_heightController.text) ?? 0; setState(() { shipmentWeight = l * w * h / volumetricRatio; }); @@ -412,7 +412,7 @@ class _CartonInfoState extends State { _box!.mixCartons = _box!.mixCartons; bool? updated = await Navigator.push( context, - CupertinoPageRoute(builder: (context) => CartonEditor(box: _box)), + CupertinoPageRoute(builder: (context) => CartonEditor(carton: _box)), ); if (updated ?? false) { var cartonModel = Provider.of(context, listen: false); diff --git a/lib/pages/customer/model/customer_model.dart b/lib/pages/customer/model/customer_model.dart index a82c24b..556895d 100644 --- a/lib/pages/customer/model/customer_model.dart +++ b/lib/pages/customer/model/customer_model.dart @@ -12,8 +12,8 @@ class CustomerModel extends BaseModel { List customers = []; List invitations = []; - late StreamSubscription? customerListener; - late StreamSubscription? invitationListener; + StreamSubscription? customerListener; + StreamSubscription? invitationListener; @override void privilegeChanged() { diff --git a/lib/pages/delivery_address/model/delivery_address_model.dart b/lib/pages/delivery_address/model/delivery_address_model.dart index fa47182..b7b90d1 100644 --- a/lib/pages/delivery_address/model/delivery_address_model.dart +++ b/lib/pages/delivery_address/model/delivery_address_model.dart @@ -95,9 +95,8 @@ class DeliveryAddressModel extends BaseModel { .collection("$path") .orderBy("full_name") .get(); - return querySnap.docs - .map((e) => - DeliveryAddress.fromMap(e.data as Map, e.id)) + return querySnap.docs + .map((e) => DeliveryAddress.fromMap(e.data(), e.id)) .toList(); } } diff --git a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart index 351d73e..30242db 100644 --- a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart +++ b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart @@ -108,8 +108,8 @@ class FcsShipmentModel extends BaseModel { .where("status", isEqualTo: fcs_shipment_confirmed_status) .get(const GetOptions(source: Source.server)); fcsShipments = snaps.docs.map((documentSnapshot) { - var fcs = FcsShipment.fromMap( - documentSnapshot.data as Map, documentSnapshot.id); + var fcs = + FcsShipment.fromMap(documentSnapshot.data(), documentSnapshot.id); return fcs; }).toList(); } catch (e) { diff --git a/lib/pages/shipment/shipment_editor.dart b/lib/pages/shipment/shipment_editor.dart index 8dda866..86d0bd9 100644 --- a/lib/pages/shipment/shipment_editor.dart +++ b/lib/pages/shipment/shipment_editor.dart @@ -70,10 +70,11 @@ class _ShipmentEditorState extends State { _fromTimeEditingController.text = "${timeFormatter.format(now)}"; _toTimeEditingController.text = "${timeFormatter.format(now)}"; // _shipment = Shipment(boxes: []); - var shipmentModel = - Provider.of(context, listen: false); - _shipment!.pickupAddress = shipmentModel.defalutAddress; - _shipment!.boxes = []; + + Shipment _s = Shipment( + pickupAddress: context.read().defalutAddress, + boxes: []); + _shipment = _s; _pickupDate.text = dateFormatter.format(now); } } @@ -87,12 +88,12 @@ class _ShipmentEditorState extends State { Widget build(BuildContext context) { MainModel mainModel = Provider.of(context); ShipmentModel pickupModel = Provider.of(context); - final shipmentNumberBox = getShipmentNumberStatus(context, _shipment!); + final shipmentNumberBox = getShipmentNumberStatus(context, _shipment); bool isLocalPickup = _selectedShipmentType == shipment_local_pickup; bool isCourierPickup = _selectedShipmentType == shipment_courier_pickup; bool isLocalDropoff = _selectedShipmentType == shipment_local_dropoff; bool isCourierDropoff = _selectedShipmentType == shipment_courier_dropoff; - var deliveryAddressModel = Provider.of(context); + final fromTimeBox = InputTime( labelTextKey: 'shipment.from', iconData: Icons.timer, @@ -122,7 +123,7 @@ class _ShipmentEditorState extends State { backgroundColor: Colors.white, )); final pickupAddressBox = DefaultDeliveryAddress( - deliveryAddress: _shipment!.pickupAddress, + deliveryAddress: _shipment?.pickupAddress, iconData: Icons.location_on, labelKey: "shipment.location", onTap: () async { @@ -130,12 +131,15 @@ class _ShipmentEditorState extends State { context, CupertinoPageRoute( builder: (context) => DeliveryAddressSelection( - deliveryAddress: _shipment!.pickupAddress, + deliveryAddress: _shipment?.pickupAddress, user: mainModel.user)), ); + if (address == null) return; + setState(() { - _shipment!.pickupAddress = address; + Shipment _s = Shipment(pickupAddress: address); + _shipment = _s; }); }, ); @@ -230,17 +234,18 @@ class _ShipmentEditorState extends State { color: primaryColor, ), onPressed: () async { - Carton box = await Navigator.push( + Carton? box = await Navigator.push( context, CupertinoPageRoute( builder: (context) => ShipmentBoxEditor()), ); + if (box == null) return; _addBox(box); }, ), ), Column( - children: getBoxList(context, _shipment!.boxes), + children: getBoxList(context, _shipment?.boxes ?? []), ), _isNew ? createBtn : updateBtn, ], @@ -324,6 +329,6 @@ class _ShipmentEditorState extends State { } isDataChanged() { - return _shipment!.boxes.isNotEmpty; + return _shipment?.boxes.isNotEmpty; } } diff --git a/lib/pages/shipment/widgets.dart b/lib/pages/shipment/widgets.dart index af2b342..b11d98d 100644 --- a/lib/pages/shipment/widgets.dart +++ b/lib/pages/shipment/widgets.dart @@ -3,21 +3,21 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:flutter/material.dart'; -Widget getShipmentNumberStatus(BuildContext context, Shipment shipment) { +Widget getShipmentNumberStatus(BuildContext context, Shipment? shipment) { return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ LocalText( context, '', - text: shipment.shipmentNumber ?? "", + text: shipment?.shipmentNumber ?? "", color: primaryColor, fontSize: 18, fontWeight: FontWeight.bold, ), Padding( padding: const EdgeInsets.only(left: 8.0), - child: Chip(label: Text(shipment.status ?? "")), + child: Chip(label: Text(shipment?.status ?? "")), ), ], ); diff --git a/lib/pages/widgets/delivery_address_selection.dart b/lib/pages/widgets/delivery_address_selection.dart index 22f6d79..fc490f5 100644 --- a/lib/pages/widgets/delivery_address_selection.dart +++ b/lib/pages/widgets/delivery_address_selection.dart @@ -64,8 +64,7 @@ class _DeliveryAddressSelectionState extends State { bool? updated = await Navigator.of(context).push(CupertinoPageRoute( builder: (context) => DeliveryAddressEditor(user: widget.user))); - if (updated == null) return; - if (updated) { + if (updated ?? false) { _getDeliverAddresses(); } }, @@ -115,10 +114,10 @@ class _DeliveryAddressSelectionState extends State { } _edit(BuildContext context, DeliveryAddress deliveryAddress) async { - bool updated = await Navigator.of(context).push(CupertinoPageRoute( + bool? updated = await Navigator.of(context).push(CupertinoPageRoute( builder: (context) => DeliveryAddressEditor( user: widget.user, deliveryAddress: deliveryAddress))); - if (updated) { + if (updated ?? false) { _getDeliverAddresses(); } }