update rate
This commit is contained in:
@@ -7,6 +7,9 @@ import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'model/shipment_rate_model.dart';
|
||||
|
||||
class CustomEditor extends StatefulWidget {
|
||||
final CustomDuty custom;
|
||||
@@ -22,6 +25,7 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
|
||||
bool _isLoading = false;
|
||||
CustomDuty _custom = new CustomDuty();
|
||||
bool _isNew = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -30,6 +34,8 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
_custom = widget.custom;
|
||||
_productController.text = _custom.productType;
|
||||
_feeController.text = _custom.fee.toString();
|
||||
} else {
|
||||
_isNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +68,12 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
backgroundColor: primaryColor,
|
||||
title:
|
||||
Text(AppTranslations.of(context).text("rate.custom.form.title")),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: _delete,
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(18),
|
||||
@@ -76,9 +88,8 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
],
|
||||
),
|
||||
),
|
||||
widget.custom == null
|
||||
? fcsButton(context, "Create", callack: () {})
|
||||
: fcsButton(context, "Save", callack: () {}),
|
||||
fcsButton(context, getLocalString(context, "btn.save"),
|
||||
callack: _save),
|
||||
SizedBox(height: 10)
|
||||
],
|
||||
),
|
||||
@@ -86,4 +97,53 @@ class _CustomEditorState extends State<CustomEditor> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_save() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
CustomDuty _customduty = CustomDuty(
|
||||
productType: _productController.text,
|
||||
fee: double.parse(_feeController.text));
|
||||
if (_isNew) {
|
||||
await shipmentRateModel.addCustomDuty(_customduty);
|
||||
} else {
|
||||
_customduty.id = widget.custom.id;
|
||||
await shipmentRateModel.updateCustomDuty(_customduty);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_delete() {
|
||||
showConfirmDialog(
|
||||
context, "cargo.edit.delete.confirm", _deleteCustomDuty);
|
||||
}
|
||||
|
||||
_deleteCustomDuty() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
await shipmentRateModel.deleteCustomDuty(widget.custom.id);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user