update carton from packages

This commit is contained in:
2021-01-08 17:13:51 +06:30
parent f0662ff1d0
commit 32b8c5ae93
17 changed files with 321 additions and 371 deletions

View File

@@ -45,6 +45,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
DeliveryAddress _deliveryAddress = new DeliveryAddress();
List<DeliveryAddress> _deliveryAddresses = [];
List<CargoType> _cargoTypes = [];
CartonSize selectedCatonSize;
@override
void initState() {
@@ -65,6 +66,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
_widthCtl.text = _carton.width.toString();
_heightCtl.text = _carton.height.toString();
_deliveryAddress = _carton.deliveryAddress;
_getCartonSize();
}
}
@@ -75,6 +77,22 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
await addressModel.getDeliveryAddresses(_carton.userID);
}
_getCartonSize() {
var cartonSizeModel = Provider.of<CartonSizeModel>(context, listen: false);
cartonSizeModel.cartonSizes.forEach((c) {
if (c.length == _carton.length &&
c.width == _carton.width &&
c.height == _carton.height) {
selectedCatonSize = CartonSize(
id: c.id,
name: c.name,
length: c.length,
width: c.width,
height: c.height);
}
});
}
@override
Widget build(BuildContext context) {
final lengthBox = LengthPicker(
@@ -105,7 +123,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
],
);
final createBtn = LocalButton(
textKey: "box.new_carton_btn",
textKey: widget.isNew ? "box.new_carton_btn" : "box.cargo.save.btn",
callBack: _creatCarton,
);
@@ -193,7 +211,6 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
);
}
CartonSize selectedCatonSize;
Widget cartonSizeDropdown() {
List<CartonSize> _cartonSizes =
Provider.of<CartonSizeModel>(context).getCartonSizes;
@@ -307,7 +324,6 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
carton.userID = _carton.userID;
carton.cargoTypes = _cargoTypes;
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
// carton.cartonSizeID = selectedCatonSize?.id;
carton.length = l;
carton.width = w;
carton.height = h;
@@ -323,7 +339,8 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
Navigator.pop(context, _c);
} else {
await cartonModel.updateCarton(carton);
Navigator.pop(context, carton);
Carton _c = await cartonModel.getCarton(_carton.id);
Navigator.pop(context, _c);
}
} catch (e) {
showMsgDialog(context, "Error", e.toString());