update package detal list and update cargo type input in carton section
This commit is contained in:
@@ -7,7 +7,6 @@ import 'package:fcs/domain/entities/package.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/carton/carton_image_upload_editor.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
import 'package:fcs/pages/package/model/package_model.dart';
|
||||
import 'package:fcs/pages/widgets/display_text.dart';
|
||||
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
@@ -28,6 +27,7 @@ import 'carton_package_editor.dart';
|
||||
import 'mix_carton/mix_carton_editor.dart';
|
||||
import 'mix_carton_detail_list.dart';
|
||||
import 'model/carton_model.dart';
|
||||
import 'model/package_selection_model.dart';
|
||||
import 'package_detail_list.dart';
|
||||
import 'print_qr_code_page.dart';
|
||||
|
||||
@@ -48,10 +48,11 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
List<CargoType> _cargoTypes = [];
|
||||
List<CargoType> _surchareItems = [];
|
||||
List<Carton> _mixCartons = [];
|
||||
List<Package> _packages = [];
|
||||
double totalWeight = 0.0;
|
||||
double totalSurchargeCount = 0.0;
|
||||
CartonSize? standardSize;
|
||||
|
||||
double _totalWeight = 0.0;
|
||||
int _packageCount = 0;
|
||||
|
||||
CartonSize? _standardSize;
|
||||
FcsShipment? _shipment;
|
||||
|
||||
@override
|
||||
@@ -77,7 +78,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
bool isStandartSize = sameLength && sameWidth && sameHeight;
|
||||
if (isStandartSize) {
|
||||
_carton.cartonSizeType = standardCarton;
|
||||
standardSize = cartonSizes.firstWhere((size) =>
|
||||
_standardSize = cartonSizes.firstWhere((size) =>
|
||||
size.length == _carton.length &&
|
||||
size.width == _carton.width &&
|
||||
size.height == _carton.height);
|
||||
@@ -89,32 +90,11 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
_carton.cartonSizeType = customCarton;
|
||||
}
|
||||
|
||||
if (widget.carton.fcsShipmentID != null &&
|
||||
widget.carton.fcsShipmentID != '') {
|
||||
var s = await context
|
||||
.read<FcsShipmentModel>()
|
||||
.getFcsShipment(widget.carton.fcsShipmentID!);
|
||||
_shipment = s;
|
||||
}
|
||||
await Future.wait(
|
||||
[_loadFcsShipment(), _loadPackageCount(), _loadMixCargoes()]);
|
||||
|
||||
if (_carton.cartonType == carton_from_packages) {
|
||||
_packages = await context
|
||||
.read<PackageModel>()
|
||||
.getPackagesByIds(_carton.packageIDs);
|
||||
}
|
||||
|
||||
if (_carton.cartonType == mix_carton) {
|
||||
_mixCartons = await context
|
||||
.read<CartonModel>()
|
||||
.getCartonsByIds(_carton.cartonIDs);
|
||||
_cargoTypes.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
_surchareItems.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
}
|
||||
|
||||
totalWeight =
|
||||
_totalWeight =
|
||||
_carton.cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
totalSurchargeCount =
|
||||
_surchareItems.fold(0, (sum, value) => sum + value.qty);
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
}
|
||||
@@ -124,12 +104,50 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadFcsShipment() async {
|
||||
if (widget.carton.fcsShipmentID != null &&
|
||||
widget.carton.fcsShipmentID != '') {
|
||||
var s = await context
|
||||
.read<FcsShipmentModel>()
|
||||
.getFcsShipment(widget.carton.fcsShipmentID!);
|
||||
_shipment = s;
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadPackageCount() async {
|
||||
if (_carton.cartonType == carton_from_packages) {
|
||||
int? count = await context.read<PackageSelectionModel>().getPackageCount(
|
||||
senderId: widget.carton.senderID ?? "",
|
||||
consigneeId: widget.carton.consigneeID ?? "",
|
||||
shipmentId: widget.carton.fcsShipmentID ?? "");
|
||||
_packageCount = count ?? 0;
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadMixCargoes() async {
|
||||
if (_carton.cartonType == mix_carton) {
|
||||
_mixCartons =
|
||||
await context.read<CartonModel>().getCartonsByIds(_carton.cartonIDs);
|
||||
_cargoTypes.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
_surchareItems.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var fromPackage = _carton.cartonType == carton_from_packages;
|
||||
|
||||
String? boxDimension = _carton.cartonSizeType == standardCarton
|
||||
? "${standardSize?.name} - ${standardSize?.length.toInt()}”x${standardSize?.width.toInt()}”x${standardSize?.height.toInt()}”"
|
||||
? "${_standardSize?.name} - ${_standardSize?.length.toInt()}”x${_standardSize?.width.toInt()}”x${_standardSize?.height.toInt()}”"
|
||||
: _carton.cartonSizeType == customCarton
|
||||
? "${_carton.length.toInt()}”x${_carton.width.toInt()}”x${_carton.height.toInt()}”"
|
||||
: null;
|
||||
@@ -178,15 +196,19 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
|
||||
final packageLengthBox = DisplayText(
|
||||
showLabelLink: true,
|
||||
subText: Text(numberFormatter.format(_packages.length)),
|
||||
subText: Text(numberFormatter.format(_packageCount)),
|
||||
labelTextKey: "box.package",
|
||||
onTapLabel: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => PackageDetailList(
|
||||
cartonNumber: _carton.cartonNumber ?? '',
|
||||
packages: _packages)));
|
||||
cartonNumber: _carton.cartonNumber ?? '',
|
||||
packageCount: _packageCount,
|
||||
senderID: _carton.senderID ?? "",
|
||||
consingeeID: _carton.consigneeID ?? "",
|
||||
fcsShipmentID: _carton.fcsShipmentID ?? "",
|
||||
)));
|
||||
},
|
||||
);
|
||||
|
||||
@@ -278,7 +300,8 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
_cargoTypes.isNotEmpty
|
||||
? Padding(
|
||||
padding: EdgeInsets.only(right: 0),
|
||||
child: Text("${removeTrailingZeros(totalWeight)} lb",
|
||||
child: Text(
|
||||
"${twoDecimalFormatted(double.tryParse(removeTrailingZeros(_totalWeight)) ?? 0)} lb",
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(color: Colors.black54, fontSize: 15)))
|
||||
: const SizedBox()
|
||||
@@ -307,7 +330,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
color: Colors.black, fontSize: 15),
|
||||
),
|
||||
Text(
|
||||
"${removeTrailingZeros(e.value.weight)} lb",
|
||||
"${twoDecimalFormatted(double.tryParse(removeTrailingZeros(e.value.weight)) ?? 0)} lb",
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 15))
|
||||
@@ -528,7 +551,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(child: cartonSizeBox),
|
||||
_packages.isEmpty
|
||||
_packageCount == 0
|
||||
? const SizedBox()
|
||||
: Flexible(child: packageLengthBox),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user