diff --git a/lib/domain/entities/carton.dart b/lib/domain/entities/carton.dart index c6fded6..803be65 100644 --- a/lib/domain/entities/carton.dart +++ b/lib/domain/entities/carton.dart @@ -36,10 +36,11 @@ class Carton { String? mixCartonNumber; String? cartonSizeID; String? cartonSizeName; + String? deliveryType; String? cartonSizeType; - String? cartonStandardSize; + double cartonWeight; - String? billTo; + String? billTo; bool isSelected; int rate; @@ -51,7 +52,6 @@ class Carton { String? remark; DateTime? arrivedDate; String? cartonNumber; - String? deliveryCarton; List packageIDs; List packages; @@ -163,12 +163,11 @@ class Carton { this.cartonSizeID, this.cartonSizeName, this.cartonSizeType, - this.cartonStandardSize, - this.deliveryCarton, + this.deliveryType, this.mixBoxType, this.mixCartons = const [], this.mixCartonIDs = const [], - this.cartonWeight =0, + this.cartonWeight = 0, this.photoUrls = const [], this.isSelected = false}); @@ -209,7 +208,7 @@ class Carton { List>.from(map['mix_cartons'] ?? []); var _mixCartons = mixCartonsMaps.map((e) => Carton.fromMap(e, e["id"])).toList(); - List _photoUrls = + List _photoUrls = map['photo_urls'] == null ? [] : List.from(map['photo_urls']); return Carton( @@ -243,7 +242,7 @@ class Carton { senderName: map['sender_name'], mixCartonIDs: List.from(map['mix_carton_ids'] ?? []), cartonWeight: (map['carton_weight'] ?? 0).toDouble(), - photoUrls: _photoUrls, + photoUrls: _photoUrls, ); } diff --git a/lib/pages/carton/carton_info.dart b/lib/pages/carton/carton_info.dart index c87eb82..3eb6393 100644 --- a/lib/pages/carton/carton_info.dart +++ b/lib/pages/carton/carton_info.dart @@ -17,6 +17,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; +import '../../domain/entities/carton_size.dart'; import '../widgets/local_button.dart'; import 'carton_package_editor.dart'; import 'mix_carton/mix_carton_editor.dart'; @@ -40,8 +41,9 @@ class _CartonInfoState extends State { List _surchareItems = []; List _mixCartons = []; List _packages = []; - double totalWeight=0.0; - double totalSurchargeCount=0.0; + double totalWeight = 0.0; + double totalSurchargeCount = 0.0; + CartonSize? standardSize; @override void initState() { @@ -51,13 +53,14 @@ class _CartonInfoState extends State { } _init() async { - _carton.billTo = billToSender; - _carton.cartonSizeType=standardCarton; + _carton.billTo = billToConsignee; + _carton.cartonSizeType = customCarton; _carton.cartonType = carton_from_packages; multiImgController.setImageUrls = _carton.photos; _cargoTypes = _carton.cargoTypes.where((e) => !e.isCutomDuty).toList(); _surchareItems = _carton.cargoTypes.where((e) => e.isCutomDuty).toList(); if (_carton.cartonType == carton_from_packages) { + _carton.deliveryType = delivery_caton; _packages = await context .read() .getPackagesByIds(_carton.packageIDs); @@ -72,16 +75,20 @@ class _CartonInfoState extends State { if (mounted) { setState(() {}); } - _carton.cartonType="Carton for packages"; - totalWeight = + _carton.cartonType = "Carton for packages"; + totalWeight = _carton.cargoTypes.fold(0, (sum, value) => sum + value.weight); - totalSurchargeCount = + totalSurchargeCount = _surchareItems.fold(0, (sum, value) => sum + value.qty); } @override Widget build(BuildContext context) { - + String? boxDimension = _carton.cartonSizeType == standardCarton + ? "${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; final cartonTypeBox = DisplayText( text: _carton.cartonNumber, @@ -90,8 +97,10 @@ class _CartonInfoState extends State { final cartonQrBox = DisplayText(iconData: AntDesign.qrcode); final cartonSubTypeBox = DisplayText( - text: _carton.cartonType==carton_from_packages ? "Carton for packages":"Mix carton", - subText:Text( "${_carton.cartonStandardSize}"), + text: _carton.cartonType == carton_from_packages + ? "Carton for packages" + : "Mix carton", + subText: boxDimension == null ? null : Text("$boxDimension"), labelTextKey: "box.carton.type", ); @@ -101,19 +110,19 @@ class _CartonInfoState extends State { ); final deliveryBox = DisplayText( - text: _carton.deliveryCarton, + text: _carton.deliveryType, labelTextKey: "box.delivery_type", ); final senderBox = DisplayText( - text: _carton.senderName== null ? "" : _carton.senderName, - subText: Text(_carton.senderFCSID?? "", style: textStyle), + text: _carton.senderName == null ? "" : _carton.senderName, + subText: Text(_carton.senderFCSID ?? "", style: textStyle), labelTextKey: "box.name", ); final consigneeNameBox = DisplayText( text: _carton.userName != null ? _carton.userName : "", - subText: Text(_carton.fcsID?? "", style: textStyle), + subText: Text(_carton.fcsID ?? "", style: textStyle), labelTextKey: "processing.consignee.name", ); @@ -183,7 +192,6 @@ class _CartonInfoState extends State { style: TextStyle(color: Colors.black54, fontSize: 15))) ], ), - //), Container( child: Padding( padding: const EdgeInsets.only(right: 100), @@ -346,20 +354,21 @@ class _CartonInfoState extends State { child: cartonQrBox, ), ]), - Row(children: [Flexible(child: cartonSubTypeBox),],), + Row( + children: [ + Flexible(child: cartonSubTypeBox), + ], + ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Flexible(child: shipmentBox), _mixCartons.isEmpty - ? - Flexible(child: deliveryBox):const SizedBox(), + ? Flexible(child: deliveryBox) + : const SizedBox(), ], ), - _mixCartons.isEmpty - ? - userRowBox: - const SizedBox(), + _mixCartons.isEmpty ? userRowBox : const SizedBox(), _packages.isEmpty ? const SizedBox() : Padding( diff --git a/lib/pages/carton/carton_package_editor.dart b/lib/pages/carton/carton_package_editor.dart index a13be1a..595d07a 100644 --- a/lib/pages/carton/carton_package_editor.dart +++ b/lib/pages/carton/carton_package_editor.dart @@ -16,6 +16,7 @@ import '../../domain/entities/package.dart'; import '../../domain/entities/user.dart'; import '../fcs_shipment/model/fcs_shipment_model.dart'; import '../main/util.dart'; +import '../package/model/package_model.dart'; import '../widgets/local_text.dart'; import '../widgets/progress.dart'; import '../widgets/step_widget.dart'; @@ -70,6 +71,7 @@ class _CartonPackageEditorState extends State { } _init() async { + context.read().clearSelection(); _sender = User( name: widget.carton.senderName, fcsID: widget.carton.senderFCSID, @@ -81,18 +83,23 @@ class _CartonPackageEditorState extends State { fcsID: widget.carton.fcsID); _billToValue = widget.carton.billTo ?? billToSender; - _selectedDeliveryType = delivery_caton; - _cartonSizeType = customCarton; + _selectedDeliveryType = widget.carton.deliveryType ?? delivery_caton; + _cartonSizeType = widget.carton.cartonSizeType ?? customCarton; _length = widget.carton.length; _width = widget.carton.width; _height = widget.carton.height; + _cargoTypes = widget.carton.cargoTypes.where((e) => !e.isCutomDuty).toList(); + _surchareItems = widget.carton.cargoTypes.where((e) => e.isCutomDuty).toList(); var s = await context .read() .getFcsShipment(widget.carton.fcsShipmentID ?? ""); _shipment = s; - context.read().clearSelection(); + _packages = await context + .read() + .getPackagesByIds(widget.carton.packageIDs); + if (mounted) { setState(() {}); } diff --git a/lib/pages/carton/model/carton_selection_model.dart b/lib/pages/carton/model/carton_selection_model.dart index 84e84be..b4b47f3 100644 --- a/lib/pages/carton/model/carton_selection_model.dart +++ b/lib/pages/carton/model/carton_selection_model.dart @@ -144,4 +144,5 @@ class CartonSelectionModel extends BaseModel { cartons.clear(); query = ""; } + } diff --git a/lib/pages/carton/model/package_selection_model.dart b/lib/pages/carton/model/package_selection_model.dart index 3f7e0d0..c25e9be 100644 --- a/lib/pages/carton/model/package_selection_model.dart +++ b/lib/pages/carton/model/package_selection_model.dart @@ -102,6 +102,10 @@ class PackageSelectionModel extends BaseModel { } } + addSelectedPackage(List list){ + selectedPackageList = list; + } + Future _refresh( {required String shipmentId, required String senderId, diff --git a/lib/pages/carton/package_selection_widget.dart b/lib/pages/carton/package_selection_widget.dart index 9926920..2d46594 100644 --- a/lib/pages/carton/package_selection_widget.dart +++ b/lib/pages/carton/package_selection_widget.dart @@ -60,6 +60,8 @@ class _PackageSelectionWidgetState extends State { consigneeId: widget.consignee.id!, senderId: widget.sender.id!); + searchModel.addSelectedPackage(widget.packages); + _controller.text = searchModel.query; _query = searchModel.query; if (mounted) {