update carton info
This commit is contained in:
@@ -90,9 +90,9 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
cargoTypes: [],
|
||||
packages: [],
|
||||
);
|
||||
_lengthController.text = "";
|
||||
_widthController.text = "";
|
||||
_heightController.text = "";
|
||||
_lengthController.text = "0";
|
||||
_widthController.text = "0";
|
||||
_heightController.text = "0";
|
||||
_isNew = true;
|
||||
_selectedCartonType = carton_from_packages;
|
||||
_selectedMixType = mix_delivery;
|
||||
@@ -256,28 +256,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
});
|
||||
});
|
||||
|
||||
final _cartonTitleBox = Container(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text("Cartons (${_cartons.length})"),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
Carton _carton = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => PackageCartonEditor()),
|
||||
);
|
||||
_addCarton(_carton);
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final cartonTitleBox = Container(
|
||||
child: LocalTitle(
|
||||
textKey: "boxes.title",
|
||||
@@ -287,26 +265,92 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
Carton _carton = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => PackageCartonEditor()),
|
||||
);
|
||||
_addCarton(_carton);
|
||||
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||
if (_user == null && isFromPackages) {
|
||||
showMsgDialog(context, "Error", "Please select customer");
|
||||
return;
|
||||
}
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
return;
|
||||
}
|
||||
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
double h = double.parse(_heightController.text, (s) => 0);
|
||||
|
||||
Carton carton = Carton();
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _selectedCartonType;
|
||||
carton.fcsShipmentID =
|
||||
_isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
carton.userID = _user?.id;
|
||||
carton.packages =
|
||||
_carton.packages.where((e) => e.isChecked).toList();
|
||||
|
||||
carton.cargoTypes = _carton.cargoTypes;
|
||||
carton.length = l;
|
||||
carton.width = w;
|
||||
carton.height = h;
|
||||
|
||||
carton.deliveryAddress = _carton.deliveryAddress;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
PackageCartonEditor(carton: carton, isNew: _isNew)),
|
||||
);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
final mixTypeBox = Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: LocalRadioButtons(
|
||||
readOnly: !_isNew,
|
||||
values: boxModel.mixTypes,
|
||||
selectedValue: _selectedMixType,
|
||||
callback: (v) {
|
||||
setState(() {
|
||||
_selectedMixType = v;
|
||||
});
|
||||
}));
|
||||
padding: EdgeInsets.only(top: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 5),
|
||||
child: LocalText(
|
||||
context,
|
||||
"box.mix_type",
|
||||
color: primaryColor,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.bold,
|
||||
)),
|
||||
Row(
|
||||
children: boxModel.mixTypes.map((e) {
|
||||
return Row(
|
||||
children: [
|
||||
Radio(
|
||||
value: e,
|
||||
groupValue: _selectedMixType,
|
||||
activeColor: primaryColor,
|
||||
onChanged: (v) {
|
||||
setState(() {
|
||||
_selectedMixType = v;
|
||||
});
|
||||
},
|
||||
),
|
||||
Text(e),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final mixcartonTitleBox = Container(
|
||||
child: LocalTitle(
|
||||
@@ -316,8 +360,8 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
Carton _carton = await Navigator.push(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (context) => MixCartonEditor()),
|
||||
);
|
||||
@@ -401,7 +445,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
_isNew ? createBtn : saveBtn,
|
||||
createBtn,
|
||||
SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
@@ -522,78 +566,77 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
}
|
||||
|
||||
_save() async {
|
||||
bool isFromShipment = _selectedCartonType == carton_from_shipments;
|
||||
bool isSmallBag = _selectedCartonType == carton_small_bag;
|
||||
if (_user == null && (isFromShipment || isSmallBag)) {
|
||||
showMsgDialog(context, "Error", "Please select customer");
|
||||
return;
|
||||
}
|
||||
if (_fcsShipment == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
return;
|
||||
}
|
||||
if ((_carton.cargoTypes?.length ?? 0) == 0 &&
|
||||
(isFromShipment || isSmallBag)) {
|
||||
showMsgDialog(context, "Error", "Expect at least one cargo type");
|
||||
return;
|
||||
}
|
||||
double l = double.parse(_lengthController.text, (s) => 0);
|
||||
double w = double.parse(_widthController.text, (s) => 0);
|
||||
double h = double.parse(_heightController.text, (s) => 0);
|
||||
if ((l <= 0 || w <= 0 || h <= 0) && isFromShipment) {
|
||||
showMsgDialog(context, "Error", "Invalid dimension");
|
||||
return;
|
||||
}
|
||||
if (_deliveryAddress == null && (isFromShipment || isSmallBag)) {
|
||||
showMsgDialog(context, "Error", "Invalid delivery address");
|
||||
return;
|
||||
}
|
||||
if (isSmallBag && _mixCarton == null && _isNew) {
|
||||
showMsgDialog(context, "Error", "Invalid mix carton");
|
||||
return;
|
||||
}
|
||||
// bool isFromShipment = _selectedCartonType == carton_from_shipments;
|
||||
// bool isSmallBag = _selectedCartonType == carton_small_bag;
|
||||
// if (_user == null && (isFromShipment || isSmallBag)) {
|
||||
// showMsgDialog(context, "Error", "Please select customer");
|
||||
// return;
|
||||
// }
|
||||
// if (_fcsShipment == null && _isNew) {
|
||||
// showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||
// return;
|
||||
// }
|
||||
// if ((_carton.cargoTypes?.length ?? 0) == 0 &&
|
||||
// (isFromShipment || isSmallBag)) {
|
||||
// showMsgDialog(context, "Error", "Expect at least one cargo type");
|
||||
// return;
|
||||
// }
|
||||
// double l = double.parse(_lengthController.text, (s) => 0);
|
||||
// double w = double.parse(_widthController.text, (s) => 0);
|
||||
// double h = double.parse(_heightController.text, (s) => 0);
|
||||
// if ((l <= 0 || w <= 0 || h <= 0) && isFromShipment) {
|
||||
// showMsgDialog(context, "Error", "Invalid dimension");
|
||||
// return;
|
||||
// }
|
||||
// if (_deliveryAddress == null && (isFromShipment || isSmallBag)) {
|
||||
// showMsgDialog(context, "Error", "Invalid delivery address");
|
||||
// return;
|
||||
// }
|
||||
// if (isSmallBag && _mixCarton == null && _isNew) {
|
||||
// showMsgDialog(context, "Error", "Invalid mix carton");
|
||||
// return;
|
||||
// }
|
||||
|
||||
Carton carton = Carton();
|
||||
carton.id = _carton.id;
|
||||
carton.cartonType = _selectedCartonType;
|
||||
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
carton.userID = _user?.id;
|
||||
carton.cargoTypes = _carton.cargoTypes;
|
||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
carton.mixCartonID = _mixCarton?.id;
|
||||
carton.length = l;
|
||||
carton.width = w;
|
||||
carton.height = h;
|
||||
carton.deliveryAddress = _deliveryAddress;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
CartonModel cartonModel =
|
||||
Provider.of<CartonModel>(context, listen: false);
|
||||
if (_isNew) {
|
||||
await cartonModel.createCarton(carton);
|
||||
} else {
|
||||
await cartonModel.updateCarton(carton);
|
||||
}
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
// Carton carton = Carton();
|
||||
// carton.id = _carton.id;
|
||||
// carton.cartonType = _selectedCartonType;
|
||||
// carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||
// carton.userID = _user?.id;
|
||||
// carton.cargoTypes = _carton.cargoTypes;
|
||||
// carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||
// carton.mixCartonID = _mixCarton?.id;
|
||||
// carton.length = l;
|
||||
// carton.width = w;
|
||||
// carton.height = h;
|
||||
// carton.deliveryAddress = _deliveryAddress;
|
||||
// setState(() {
|
||||
// _isLoading = true;
|
||||
// });
|
||||
// try {
|
||||
// CartonModel cartonModel =
|
||||
// Provider.of<CartonModel>(context, listen: false);
|
||||
// if (_isNew) {
|
||||
// await cartonModel.createCarton(carton);
|
||||
// } else {
|
||||
// await cartonModel.updateCarton(carton);
|
||||
// }
|
||||
// Navigator.pop(context, true);
|
||||
// } catch (e) {
|
||||
// showMsgDialog(context, "Error", e.toString());
|
||||
// } finally {
|
||||
// setState(() {
|
||||
// _isLoading = false;
|
||||
// });
|
||||
// }
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
if (_isNew) {
|
||||
return _fcsShipment != null ||
|
||||
_user != null ||
|
||||
_cartons.isNotEmpty ||
|
||||
this._mixCartons.isNotEmpty;
|
||||
return false;
|
||||
// return _fcsShipment != null || _user != null;
|
||||
} else {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user