update carton and cargo type

This commit is contained in:
tzw
2025-03-12 17:49:27 +06:30
parent 05e912ea68
commit e208734dfa
32 changed files with 1141 additions and 462 deletions

View File

@@ -1,3 +1,5 @@
// ignore_for_file: use_build_context_synchronously
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/util.dart';
@@ -5,6 +7,7 @@ import 'package:fcs/pages/widgets/input_text.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';
@@ -12,19 +15,19 @@ import 'model/shipment_rate_model.dart';
class CustomEditor extends StatefulWidget {
final CargoType? custom;
CustomEditor({this.custom});
const CustomEditor({super.key, this.custom});
@override
_CustomEditorState createState() => _CustomEditorState();
}
class _CustomEditorState extends State<CustomEditor> {
TextEditingController _productController = new TextEditingController();
TextEditingController _feeController = new TextEditingController();
TextEditingController _shipmentRateController = new TextEditingController();
TextEditingController productController = TextEditingController();
TextEditingController feeController = TextEditingController();
TextEditingController shipmentRateController = TextEditingController();
bool _isLoading = false;
CargoType _custom = new CargoType();
CargoType _custom = CargoType();
bool _isNew = false;
final _customFormKey = GlobalKey<FormState>();
@@ -33,9 +36,9 @@ class _CustomEditorState extends State<CustomEditor> {
super.initState();
if (widget.custom != null) {
_custom = widget.custom!;
_productController.text = _custom.name ?? "";
_feeController.text = _custom.customDutyFee.toStringAsFixed(2);
_shipmentRateController.text = _custom.rate.toStringAsFixed(2);
productController.text = _custom.name ?? "";
feeController.text = _custom.customDutyFee.toStringAsFixed(2);
shipmentRateController.text = _custom.rate.toStringAsFixed(2);
} else {
_isNew = true;
}
@@ -49,20 +52,22 @@ class _CustomEditorState extends State<CustomEditor> {
@override
Widget build(BuildContext context) {
final productBox = InputText(
labelTextKey: 'rate.cutom.product_type',
iconData: FontAwesomeIcons.weightHanging,
autovalidateMode: AutovalidateMode.onUserInteraction,
controller: _productController,
validator: (value){
if(value==null || value.isEmpty){
return "Please insert product type";
}
return null;
},);
labelTextKey: 'rate.cutom.product_type',
iconData: FontAwesomeIcons.weightHanging,
autovalidateMode: AutovalidateMode.onUserInteraction,
controller: productController,
validator: (value) {
if (value == null || value.isEmpty) {
return "Please insert product type";
}
return null;
},
);
final feeBox = InputText(
labelTextKey: 'rate.custom.fee',
iconData: Icons.attach_money,
controller: _feeController,
iconData: Fontisto.dollar,
controller: feeController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || value.isEmpty) {
@@ -74,8 +79,8 @@ class _CustomEditorState extends State<CustomEditor> {
final shipmentRateBox = InputText(
labelTextKey: 'rate.custom.shipment_rate',
iconData: Icons.attach_money,
controller: _shipmentRateController,
iconData: Fontisto.dollar,
controller: shipmentRateController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || value.isEmpty) {
@@ -128,7 +133,7 @@ class _CustomEditorState extends State<CustomEditor> {
),
fcsButton(context, getLocalString(context, "btn.save"),
callack: _save),
SizedBox(height: 10)
SizedBox(height: 30)
],
),
),
@@ -148,15 +153,15 @@ class _CustomEditorState extends State<CustomEditor> {
try {
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
CargoType _customduty = CargoType(
name: _productController.text,
customDutyFee: double.parse(_feeController.text),
rate: double.parse(_shipmentRateController.text));
CargoType customduty = CargoType(
name: productController.text,
customDutyFee: double.parse(feeController.text),
rate: double.parse(shipmentRateController.text));
if (_isNew) {
await shipmentRateModel.addCustomDuty(_customduty);
await shipmentRateModel.addCustomDuty(customduty);
} else {
_customduty.id = this._custom.id;
await shipmentRateModel.updateCustomDuty(_customduty);
customduty.id = _custom.id;
await shipmentRateModel.updateCustomDuty(customduty);
}
Navigator.pop(context);
} catch (e) {
@@ -180,7 +185,7 @@ class _CustomEditorState extends State<CustomEditor> {
try {
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
await shipmentRateModel.deleteCustomDuty(this._custom.id!);
await shipmentRateModel.deleteCustomDuty(_custom.id!);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
@@ -193,15 +198,15 @@ class _CustomEditorState extends State<CustomEditor> {
isDataChanged() {
if (_isNew) {
return _productController.text != "" ||
_feeController.text != "" ||
_shipmentRateController.text != "";
return productController.text != "" ||
feeController.text != "" ||
shipmentRateController.text != "";
} else {
CargoType _customduty = CargoType(
name: _productController.text,
customDutyFee: double.parse(_feeController.text),
rate: double.parse(_shipmentRateController.text));
return this._custom.isChangedForEditCustomDuty(_customduty);
CargoType customduty = CargoType(
name: productController.text,
customDutyFee: double.parse(feeController.text),
rate: double.parse(shipmentRateController.text));
return _custom.isChangedForEditCustomDuty(customduty);
}
}
}