update rate
This commit is contained in:
@@ -6,6 +6,9 @@ import 'package:fcs/pages/widgets/input_text.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'model/shipment_rate_model.dart';
|
||||
|
||||
class CargoEditor extends StatefulWidget {
|
||||
final CargoType cargo;
|
||||
@@ -21,6 +24,8 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
|
||||
bool _isLoading = false;
|
||||
CargoType _cargo;
|
||||
bool _isNew = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -28,6 +33,8 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
_cargo = widget.cargo;
|
||||
_descController.text = _cargo.name;
|
||||
_rateController.text = _cargo.rate.toString();
|
||||
} else {
|
||||
_isNew = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +64,12 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("cargo.form.title")),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: _delete,
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(18),
|
||||
@@ -71,9 +84,8 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
],
|
||||
),
|
||||
),
|
||||
widget.cargo == null
|
||||
? fcsButton(context, "Create", callack: () {})
|
||||
: fcsButton(context, "Save", callack: () {}),
|
||||
fcsButton(context, getLocalString(context, "btn.save"),
|
||||
callack: _save),
|
||||
SizedBox(height: 10)
|
||||
],
|
||||
),
|
||||
@@ -81,4 +93,52 @@ class _CargoEditorState extends State<CargoEditor> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_save() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
CargoType _cargo = CargoType(
|
||||
name: _descController.text, rate: double.parse(_rateController.text));
|
||||
if (_isNew) {
|
||||
await shipmentRateModel.addCargoType(_cargo);
|
||||
} else {
|
||||
_cargo.id = widget.cargo.id;
|
||||
await shipmentRateModel.updateCargoType(_cargo);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
_delete() {
|
||||
showConfirmDialog(
|
||||
context, "cargo_type.edit.delete.confirm", _deleteCargoType);
|
||||
}
|
||||
|
||||
_deleteCargoType() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
await shipmentRateModel.deleteCargoType(widget.cargo.id);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user