add prompt confirmation and update carton

This commit is contained in:
Thinzar Win
2020-12-08 20:24:15 +06:30
parent 1a7b1ce97b
commit 20477b6915
39 changed files with 637 additions and 259 deletions

View File

@@ -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);
}
}
}