null safety
This commit is contained in:
@@ -29,7 +29,7 @@ import 'shipment_box_editor.dart';
|
||||
import 'widgets.dart';
|
||||
|
||||
class ShipmentEditor extends StatefulWidget {
|
||||
final Shipment shipment;
|
||||
final Shipment? shipment;
|
||||
ShipmentEditor({this.shipment});
|
||||
|
||||
@override
|
||||
@@ -45,12 +45,12 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
TextEditingController _toTimeEditingController = new TextEditingController();
|
||||
TextEditingController _pickupDate = new TextEditingController();
|
||||
|
||||
Shipment _shipment;
|
||||
Shipment? _shipment;
|
||||
bool _isLoading = false;
|
||||
var now = new DateTime.now();
|
||||
bool _isNew;
|
||||
late bool _isNew;
|
||||
|
||||
String _selectedShipmentType;
|
||||
String? _selectedShipmentType;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -59,20 +59,21 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
if (widget.shipment != null) {
|
||||
_isNew = false;
|
||||
_shipment = widget.shipment;
|
||||
_selectedShipmentType = _shipment.shipmentType;
|
||||
_fromTimeEditingController.text = _shipment.pickupTimeStart;
|
||||
_toTimeEditingController.text = _shipment.pickupTimeEnd;
|
||||
_pickupDate.text = dateFormatter.format(_shipment.pickupDate ?? now);
|
||||
_selectedShipmentType = _shipment!.shipmentType;
|
||||
_fromTimeEditingController.text = _shipment!.pickupTimeStart ?? "";
|
||||
_toTimeEditingController.text = _shipment!.pickupTimeEnd ?? "";
|
||||
_pickupDate.text = dateFormatter.format(_shipment!.pickupDate ?? now);
|
||||
} else {
|
||||
_isNew = true;
|
||||
_selectedShipmentType = shipment_local_pickup;
|
||||
_pickupDate.text = dateFormatter.format(now);
|
||||
_fromTimeEditingController.text = "${timeFormatter.format(now)}";
|
||||
_toTimeEditingController.text = "${timeFormatter.format(now)}";
|
||||
_shipment = Shipment(boxes: []);
|
||||
// _shipment = Shipment(boxes: []);
|
||||
var shipmentModel =
|
||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
||||
_shipment.pickupAddress = shipmentModel.defalutAddress;
|
||||
_shipment!.pickupAddress = shipmentModel.defalutAddress;
|
||||
_shipment!.boxes = [];
|
||||
_pickupDate.text = dateFormatter.format(now);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +87,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
Widget build(BuildContext context) {
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
ShipmentModel pickupModel = Provider.of<ShipmentModel>(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;
|
||||
@@ -121,20 +122,20 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
backgroundColor: Colors.white,
|
||||
));
|
||||
final pickupAddressBox = DefaultDeliveryAddress(
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
deliveryAddress: _shipment!.pickupAddress,
|
||||
iconData: Icons.location_on,
|
||||
labelKey: "shipment.location",
|
||||
onTap: () async {
|
||||
DeliveryAddress address = await Navigator.push<DeliveryAddress>(
|
||||
DeliveryAddress? address = await Navigator.push<DeliveryAddress>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => DeliveryAddressSelection(
|
||||
deliveryAddress: _shipment.pickupAddress,
|
||||
deliveryAddress: _shipment!.pickupAddress,
|
||||
user: mainModel.user)),
|
||||
);
|
||||
if (address == null) return;
|
||||
setState(() {
|
||||
_shipment.pickupAddress = address;
|
||||
_shipment!.pickupAddress = address;
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -142,7 +143,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
FcsIDIcon(),
|
||||
Expanded(
|
||||
child: DisplayText(
|
||||
text: mainModel.setting.usaAddress,
|
||||
text: mainModel.setting!.usaAddress,
|
||||
),
|
||||
)
|
||||
]);
|
||||
@@ -194,7 +195,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
LocalRadioButtons(
|
||||
values: pickupModel.shipmentTypes,
|
||||
selectedValue: _selectedShipmentType,
|
||||
callback: (v) {
|
||||
callback: (String? v) {
|
||||
setState(() {
|
||||
_selectedShipmentType = v;
|
||||
});
|
||||
@@ -239,7 +240,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
),
|
||||
),
|
||||
Column(
|
||||
children: getBoxList(context, _shipment.boxes),
|
||||
children: getBoxList(context, _shipment!.boxes),
|
||||
),
|
||||
_isNew ? createBtn : updateBtn,
|
||||
],
|
||||
@@ -276,7 +277,7 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
_addBox(Carton box) {
|
||||
if (box == null) return;
|
||||
box.cartonType = carton_from_shipments;
|
||||
_shipment.boxes.add(box);
|
||||
_shipment!.boxes.add(box);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@@ -287,15 +288,15 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
|
||||
_removeBox(Carton box) {
|
||||
if (box == null) return;
|
||||
_shipment.boxes.remove(box);
|
||||
_shipment!.boxes.remove(box);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
_save() async {
|
||||
_shipment.shipmentType = this._selectedShipmentType;
|
||||
_shipment.pickupDate = dateFormatter.parse(_pickupDate.text);
|
||||
_shipment.pickupTimeStart = _fromTimeEditingController.text;
|
||||
_shipment.pickupTimeEnd = _toTimeEditingController.text;
|
||||
_shipment!.shipmentType = this._selectedShipmentType;
|
||||
_shipment!.pickupDate = dateFormatter.parse(_pickupDate.text);
|
||||
_shipment!.pickupTimeStart = _fromTimeEditingController.text;
|
||||
_shipment!.pickupTimeEnd = _toTimeEditingController.text;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
@@ -303,9 +304,9 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
if (_isNew) {
|
||||
await shipmentModel.createShipment(_shipment);
|
||||
await shipmentModel.createShipment(_shipment!);
|
||||
} else {
|
||||
await shipmentModel.updateShipment(_shipment);
|
||||
await shipmentModel.updateShipment(_shipment!);
|
||||
}
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
@@ -319,10 +320,10 @@ class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
|
||||
_openCourierWebsite() {
|
||||
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
||||
launch("${mainModel.setting.courierWebsite}");
|
||||
launch("${mainModel.setting!.courierWebsite}");
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
return _shipment.boxes.isNotEmpty;
|
||||
return _shipment!.boxes.isNotEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user