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/discount_by_weight.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/main/util.dart';
@@ -6,24 +8,25 @@ 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';
class DiscountByWeightEditor extends StatefulWidget {
final DiscountByWeight? discountByWeight;
DiscountByWeightEditor({this.discountByWeight});
const DiscountByWeightEditor({super.key, this.discountByWeight});
@override
_DiscountByWeightEditorState createState() => _DiscountByWeightEditorState();
}
class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
TextEditingController _weightController = new TextEditingController();
TextEditingController _discountController = new TextEditingController();
TextEditingController weightController = TextEditingController();
TextEditingController discountController = TextEditingController();
bool _isLoading = false;
bool _isNew = false;
DiscountByWeight _discountByWeight = new DiscountByWeight();
DiscountByWeight _discountByWeight = DiscountByWeight();
final _discountFormKey = GlobalKey<FormState>();
@override
@@ -31,8 +34,8 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
super.initState();
if (widget.discountByWeight != null) {
_discountByWeight = widget.discountByWeight!;
_weightController.text = _discountByWeight.weight.toStringAsFixed(2);
_discountController.text = _discountByWeight.discount.toString();
weightController.text = _discountByWeight.weight.toStringAsFixed(2);
discountController.text = _discountByWeight.discount.toString();
_isNew = false;
} else {
_isNew = true;
@@ -49,7 +52,7 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
final weightBox = InputText(
labelTextKey: 'rate.discount.weight',
iconData: FontAwesomeIcons.weightHanging,
controller: _weightController,
controller: weightController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || value.isEmpty) {
@@ -60,8 +63,8 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
);
final discountRateBox = InputText(
labelTextKey: 'rate.discount.rate',
iconData: Icons.attach_money,
controller: _discountController,
iconData: Fontisto.dollar,
controller: discountController,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value == null || value.isEmpty) {
@@ -75,7 +78,7 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
inAsyncCall: _isLoading,
child: Scaffold(
appBar: LocalAppBar(
labelKey: 'discount.new',
labelKey: 'discount.form',
backgroundColor: Colors.white,
labelColor: primaryColor,
arrowColor: primaryColor,
@@ -114,7 +117,7 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
),
fcsButton(context, getLocalString(context, "btn.save"),
callack: _save),
SizedBox(height: 10)
SizedBox(height: 30)
],
),
),
@@ -134,14 +137,14 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
try {
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
DiscountByWeight _discount = DiscountByWeight(
weight: double.parse(_weightController.text),
discount: double.parse(_discountController.text));
DiscountByWeight discount = DiscountByWeight(
weight: double.parse(weightController.text),
discount: double.parse(discountController.text));
if (_isNew) {
await shipmentRateModel.addDiscountByWeight(_discount);
await shipmentRateModel.addDiscountByWeight(discount);
} else {
_discount.id = this._discountByWeight.id;
await shipmentRateModel.updateDiscountByWeight(_discount);
discount.id = _discountByWeight.id;
await shipmentRateModel.updateDiscountByWeight(discount);
}
Navigator.pop(context);
} catch (e) {
@@ -165,8 +168,7 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
try {
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
await shipmentRateModel
.deleteDiscountByWeight(this._discountByWeight.id!);
await shipmentRateModel.deleteDiscountByWeight(_discountByWeight.id!);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
@@ -179,12 +181,12 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
isDataChanged() {
if (_isNew) {
return _weightController.text != "" || _discountController.text != "";
return weightController.text != "" || discountController.text != "";
} else {
DiscountByWeight _discount = DiscountByWeight(
weight: double.parse(_weightController.text),
discount: double.parse(_discountController.text));
return this._discountByWeight.isChangedForEdit(_discount);
DiscountByWeight discount = DiscountByWeight(
weight: double.parse(weightController.text),
discount: double.parse(discountController.text));
return _discountByWeight.isChangedForEdit(discount);
}
}
}