add prompt confirmation and update carton
This commit is contained in:
@@ -61,9 +61,13 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
onPressed: () {
|
||||
showConfirmDialog(context, "back.button_confirm", () {
|
||||
if (isDataChanged()) {
|
||||
showConfirmDialog(context, "back.button_confirm", () {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
} else {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
@@ -144,4 +148,14 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
if (_isNew) {
|
||||
return _descController.text != "" || _rateController.text != "";
|
||||
} else {
|
||||
CargoType _cargo = CargoType(
|
||||
name: _descController.text, rate: double.parse(_rateController.text));
|
||||
return widget.cargo.isChangedForEdit(_cargo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ class CustomEditor extends StatefulWidget {
|
||||
class _CustomEditorState extends State<CustomEditor> {
|
||||
TextEditingController _productController = new TextEditingController();
|
||||
TextEditingController _feeController = new TextEditingController();
|
||||
TextEditingController _shipmentRateController = new TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
CustomDuty _custom = new CustomDuty();
|
||||
@@ -34,6 +35,9 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
_custom = widget.custom;
|
||||
_productController.text = _custom.productType;
|
||||
_feeController.text = _custom.fee.toStringAsFixed(2);
|
||||
_shipmentRateController.text = _custom.shipmentRate == null
|
||||
? ""
|
||||
: _custom.shipmentRate.toStringAsFixed(2);
|
||||
} else {
|
||||
_isNew = true;
|
||||
}
|
||||
@@ -54,6 +58,11 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
labelTextKey: 'rate.custom.fee',
|
||||
iconData: Icons.attach_money,
|
||||
controller: _feeController);
|
||||
|
||||
final shipmentRateBox = InputText(
|
||||
labelTextKey: 'rate.custom.shipment_rate',
|
||||
iconData: Icons.attach_money,
|
||||
controller: _shipmentRateController);
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
@@ -64,9 +73,13 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
CupertinoIcons.back,
|
||||
),
|
||||
onPressed: () {
|
||||
showConfirmDialog(context, "back.button_confirm", () {
|
||||
if (isDataChanged()) {
|
||||
showConfirmDialog(context, "back.button_confirm", () {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
} else {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
@@ -88,6 +101,7 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
children: <Widget>[
|
||||
productBox,
|
||||
feeBox,
|
||||
shipmentRateBox,
|
||||
SizedBox(height: 30),
|
||||
],
|
||||
),
|
||||
@@ -111,7 +125,8 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
CustomDuty _customduty = CustomDuty(
|
||||
productType: _productController.text,
|
||||
fee: double.parse(_feeController.text));
|
||||
fee: double.parse(_feeController.text),
|
||||
shipmentRate: double.parse(_shipmentRateController.text));
|
||||
print('_customduty => $_customduty');
|
||||
if (_isNew) {
|
||||
await shipmentRateModel.addCustomDuty(_customduty);
|
||||
@@ -151,4 +166,19 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
if (_isNew) {
|
||||
return _productController.text != "" ||
|
||||
_feeController.text != "" ||
|
||||
_shipmentRateController.text != "";
|
||||
} else {
|
||||
CustomDuty _customduty = CustomDuty(
|
||||
productType: _productController.text,
|
||||
fee: double.parse(_feeController.text),
|
||||
// shipmentRate: double.parse(_shipmentRateController.text)
|
||||
);
|
||||
return widget.custom.isChangedForEdit(_customduty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +63,13 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
|
||||
leading: new IconButton(
|
||||
icon: new Icon(CupertinoIcons.back),
|
||||
onPressed: () {
|
||||
showConfirmDialog(context, "back.button_confirm", () {
|
||||
if (isDataChanged()) {
|
||||
showConfirmDialog(context, "back.button_confirm", () {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
} else {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
@@ -149,4 +153,15 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
if (_isNew) {
|
||||
return _weightController.text != "" || _discountController.text != "";
|
||||
} else {
|
||||
DiscountByWeight _discount = DiscountByWeight(
|
||||
weight: double.parse(_weightController.text),
|
||||
discount: double.parse(_discountController.text));
|
||||
return widget.discountByWeight.isChangedForEdit(_discount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +29,14 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
TextEditingController _minWeight = new TextEditingController();
|
||||
TextEditingController _deliveryFee = new TextEditingController();
|
||||
TextEditingController _volumetricRatio = new TextEditingController();
|
||||
Rate rate;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
Rate rate = shipmentRateModel.rate;
|
||||
rate = shipmentRateModel.rate;
|
||||
|
||||
_minWeight.text = rate.freeDeliveryWeight?.toStringAsFixed(2) ?? "";
|
||||
_deliveryFee.text = rate.deliveryFee?.toStringAsFixed(2) ?? "";
|
||||
@@ -74,9 +75,13 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
CupertinoIcons.back,
|
||||
),
|
||||
onPressed: () {
|
||||
showConfirmDialog(context, "back.button_confirm", () {
|
||||
if (isDataChanged()) {
|
||||
showConfirmDialog(context, "back.button_confirm", () {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
} else {
|
||||
Navigator.of(context).pop();
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
@@ -130,6 +135,14 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
|
||||
}
|
||||
}
|
||||
|
||||
isDataChanged() {
|
||||
Rate _rate = new Rate(
|
||||
deliveryFee: double.parse(_deliveryFee.text),
|
||||
freeDeliveryWeight: double.parse(_minWeight.text),
|
||||
volumetricRatio: double.parse(_volumetricRatio.text));
|
||||
return rate.isChangedForEdit(_rate);
|
||||
}
|
||||
|
||||
List<MyDataRow> getCargoRows(List<CargoType> cargos) {
|
||||
return cargos.map((r) {
|
||||
return MyDataRow(
|
||||
|
||||
Reference in New Issue
Block a user