update ui

This commit is contained in:
tzw
2025-04-02 15:02:49 +06:30
parent 17ca3e2a3f
commit f1c5342ae4
16 changed files with 253 additions and 245 deletions

View File

@@ -29,7 +29,7 @@ class MixCartonSubmit extends StatefulWidget {
final OnCreateMixCarton? onCreate;
final OnPrevious? onPrevious;
const MixCartonSubmit(
{Key? key,
{super.key,
this.onCreate,
this.onPrevious,
required this.shipment,
@@ -39,8 +39,7 @@ class MixCartonSubmit extends StatefulWidget {
this.length = 0,
this.width = 0,
this.height = 0,
this.isNew = true})
: super(key: key);
this.isNew = true});
@override
State<MixCartonSubmit> createState() => _MixCartonSubmitState();
@@ -48,8 +47,8 @@ class MixCartonSubmit extends StatefulWidget {
class _MixCartonSubmitState extends State<MixCartonSubmit> {
final NumberFormat numberFormatter = NumberFormat("#,###");
Map<String?, double> _mapCargos = {};
Map<String?, double> _mapSurchargeItems = {};
final Map<String?, double> _mapCargos = {};
final Map<String?, double> _mapSurchargeItems = {};
double totalWeight = 0;
@override
@@ -60,15 +59,15 @@ class _MixCartonSubmitState extends State<MixCartonSubmit> {
_init() {
// get cargos by weight
List<CargoType> _cargoTypes = [];
List<CargoType> cargoTypes = [];
for (var c in widget.cartons) {
_cargoTypes.addAll(c.cargoTypes);
cargoTypes.addAll(c.cargoTypes);
}
_cargoTypes.sort((a, b) => a.name!.compareTo(b.name!));
cargoTypes.sort((a, b) => a.name!.compareTo(b.name!));
Map<String?, List<CargoType>> _cargosByWeight = groupCargos(_cargoTypes);
_cargosByWeight.forEach((key, value) {
Map<String?, List<CargoType>> cargosByWeight = groupCargos(cargoTypes);
cargosByWeight.forEach((key, value) {
double total = value.fold(0, (sum, item) => sum + item.weight);
_mapCargos[key] = total;
});
@@ -77,17 +76,17 @@ class _MixCartonSubmitState extends State<MixCartonSubmit> {
// get surcharge items
List<CargoType> _surchargeItems = [];
List<CargoType> surchargeItems = [];
for (var c in widget.cartons) {
_surchargeItems.addAll(c.surchareItems);
surchargeItems.addAll(c.surchareItems);
}
_surchargeItems.sort((a, b) => a.name!.compareTo(b.name!));
surchargeItems.sort((a, b) => a.name!.compareTo(b.name!));
Map<String?, List<CargoType>> _cargosByCustomDutyFee =
groupCargos(_surchargeItems);
Map<String?, List<CargoType>> cargosByCustomDutyFee =
groupCargos(surchargeItems);
_cargosByCustomDutyFee.forEach((key, value) {
cargosByCustomDutyFee.forEach((key, value) {
double total = value.fold(0, (sum, item) => sum + item.qty);
_mapSurchargeItems[key] = total;
});
@@ -99,8 +98,8 @@ class _MixCartonSubmitState extends State<MixCartonSubmit> {
Map<String?, List<CargoType>> groupCargos(List<CargoType> cargos) {
var groups = groupBy(cargos, (CargoType e) {
String? _categoryName = e.name;
return _categoryName;
String? categoryName = e.name;
return categoryName;
});
return groups;
@@ -220,22 +219,80 @@ class _MixCartonSubmitState extends State<MixCartonSubmit> {
),
);
}).toList()),
const SizedBox(height: 10),
// const SizedBox(height: 10),
// Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: _mapSurchargeItems.entries.map((e) {
// return Padding(
// padding: const EdgeInsets.symmetric(vertical: 3),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Text(
// e.key ?? "",
// style: TextStyle(color: labelColor, fontSize: 15),
// ),
// Text("${numberFormatter.format(e.value)} pc",
// style:
// TextStyle(color: labelColor, fontSize: 15))
// ],
// ),
// );
// }).toList()),
],
),
),
),
]),
);
final surChargeItemsBox = Padding(
padding: const EdgeInsets.only(top: 10),
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Padding(
padding: const EdgeInsets.only(left: 5, bottom: 5, right: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
LocalText(context, 'box.input_surcharge_item',
color: primaryColor,
fontSize: 16,
fontWeight: FontWeight.normal),
],
),
),
Container(
decoration: BoxDecoration(
border: Border.all(color: primaryColor),
borderRadius: BorderRadius.circular(5),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _mapSurchargeItems.entries.map((e) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 3),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
e.key ?? "",
style: TextStyle(color: labelColor, fontSize: 15),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
e.key ?? "",
style: TextStyle(
color: Colors.black, fontSize: 15),
),
Text(
"${removeTrailingZeros((e.value).toDouble())} pc",
textAlign: TextAlign.end,
style: TextStyle(
color: Colors.black, fontSize: 15))
],
),
Text("${numberFormatter.format(e.value)} pc",
style:
TextStyle(color: labelColor, fontSize: 15))
],
),
);
@@ -302,7 +359,12 @@ class _MixCartonSubmitState extends State<MixCartonSubmit> {
const SizedBox(height: 10),
widget.cartons.isNotEmpty ? cartonsBox : const SizedBox(),
const SizedBox(height: 10),
cargosBox,
_mapCargos.isNotEmpty ? cargosBox : const SizedBox(),
_mapSurchargeItems.isNotEmpty
? Padding(
padding: EdgeInsets.only(top: 10),
child: surChargeItemsBox)
: const SizedBox(),
const SizedBox(height: 20),
],
),