update cargo type form from rate, update carton info and form

This commit is contained in:
tzw
2024-09-25 21:49:09 +06:30
parent 1be18c08a9
commit 02e079c514
51 changed files with 1407 additions and 643 deletions

View File

@@ -18,6 +18,7 @@ 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 '../carton_size/model/carton_size_model.dart';
import '../widgets/local_button.dart';
import 'carton_package_editor.dart';
import 'mix_carton/mix_carton_editor.dart';
@@ -56,27 +57,41 @@ class _CartonInfoState extends State<CartonInfo> {
_init() async {
try {
_isLoading = true;
_carton.cartonType = carton_from_packages;
_carton.billTo = billToConsignee;
_carton.cartonSizeType = customCarton;
_multiImgController.setImageUrls = _carton.photoUrls;
_cargoTypes = _carton.cargoTypes.where((e) => !e.isCutomDuty).toList();
_surchareItems = _carton.cargoTypes.where((e) => e.isCutomDuty).toList();
_cargoTypes = _carton.cargoTypes;
_surchareItems = _carton.surchareItems;
// check carton size type
List<CartonSize> cartonSizes =
context.read<CartonSizeModel>().cartonSizes;
var sameLength = cartonSizes.any((size) => size.length == _carton.length);
var sameWidth = cartonSizes.any((size) => size.width == _carton.width);
var sameHeight = cartonSizes.any((size) => size.height == _carton.height);
bool isStandartSize = sameLength && sameWidth && sameHeight;
if (isStandartSize) {
_carton.cartonSizeType = standardCarton;
standardSize = cartonSizes.firstWhere((size) =>
size.length == _carton.length &&
size.width == _carton.width &&
size.height == _carton.height);
} else if (_carton.length == 0 &&
_carton.width == 0 &&
_carton.height == 0) {
_carton.cartonSizeType = packageCarton;
} else {
_carton.cartonSizeType = customCarton;
}
if (_carton.cartonType == carton_from_packages) {
_carton.deliveryType = delivery_caton;
_packages = await context
.read<PackageModel>()
.getPackagesByIds(_carton.packageIDs);
}
if (_carton.cartonType == carton_mix_carton) {
if (_carton.cartonType == mix_carton) {
_mixCartons = await context
.read<CartonModel>()
.getCartonsByIds(_carton.mixCartonIDs);
}
if (mounted) {
setState(() {});
.getCartonsByIds(_carton.cartonIDs);
}
totalWeight =
@@ -86,17 +101,23 @@ class _CartonInfoState extends State<CartonInfo> {
} finally {
_isLoading = false;
}
if (mounted) {
setState(() {});
}
}
@override
Widget build(BuildContext context) {
String? boxDimension = _carton.cartonSizeType == standardCarton
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()}"
: _carton.cartonSizeType == customCarton
? "${_carton.length.toInt()}”x${_carton.width.toInt()}”x${_carton.height.toInt()}"
: null;
final cartonTypeBox = DisplayText(
final cartonNumberBox = DisplayText(
text: _carton.cartonNumber,
labelTextKey: "box.number",
);
@@ -111,10 +132,12 @@ class _CartonInfoState extends State<CartonInfo> {
},
icon: Icon(AntDesign.qrcode, color: Colors.black));
final cartonSubTypeBox = DisplayText(
final cartonTypeBox = DisplayText(
text: _carton.cartonType == carton_from_packages
? "For packages"
: "Mix carton",
: _carton.cartonType == mix_carton
? carton_mix_carton
: '',
labelTextKey: "box.carton.type",
);
@@ -132,13 +155,13 @@ class _CartonInfoState extends State<CartonInfo> {
labelTextKey: "box.fcs_shipment_num",
);
final deliveryBox = DisplayText(
text: _carton.deliveryType,
final lastMileBox = DisplayText(
text: _carton.lastMile == delivery_caton ? 'Delivery' : 'Pick-up',
labelTextKey: "box.delivery_type",
);
final cartonSizeBox = DisplayText(
subText: boxDimension == null ? null : Text("$boxDimension"),
subText: Text("${boxDimension ?? 'No defined size'}"),
labelTextKey: "box.carton_size",
);
@@ -149,8 +172,8 @@ class _CartonInfoState extends State<CartonInfo> {
);
final consigneeNameBox = DisplayText(
text: _carton.userName != null ? _carton.userName : "",
subText: Text(_carton.fcsID ?? "", style: textStyle),
text: _carton.consigneeName != null ? _carton.consigneeName : "",
subText: Text(_carton.consigneeFCSID ?? "", style: textStyle),
labelTextKey: "processing.consignee.name",
);
@@ -367,30 +390,29 @@ class _CartonInfoState extends State<CartonInfo> {
padding: const EdgeInsets.only(left: 20, right: 20),
child: ListView(children: <Widget>[
Row(children: [
Flexible(child: cartonTypeBox,flex: 1),
Flexible(child: cartonNumberBox, flex: 1),
Flexible(
child: cartonQrBox,
),
]),
Row(
children: [
Flexible(child: cartonSubTypeBox),
Flexible(child: cartonTypeBox),
],
),
_mixCartons.isEmpty ? userRowBox : const SizedBox(),
fromPackage ? userRowBox : const SizedBox(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(child: billInfoBox),
fromPackage ? Flexible(child: billInfoBox) : SizedBox(),
Flexible(child: shipmentBox),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_mixCartons.isEmpty
? Flexible(child: deliveryBox)
fromPackage
? Flexible(child: lastMileBox)
: const SizedBox(),
Flexible(child: cartonSizeBox),
],
@@ -430,7 +452,9 @@ class _CartonInfoState extends State<CartonInfo> {
uploadImageBtn,
const SizedBox(height: 30),
img,
const SizedBox(height: 40),
_carton.photoUrls.isNotEmpty
? const SizedBox(height: 40)
: const SizedBox(),
deleteBtn,
const SizedBox(height: 20)
]))));
@@ -457,17 +481,22 @@ class _CartonInfoState extends State<CartonInfo> {
}
_gotoEditor() async {
bool? updated = _carton.cartonType == carton_mix_carton
? await Navigator.push<bool>(
context,
CupertinoPageRoute(
builder: (context) => MixCartonEditor(carton: _carton)),
)
: await Navigator.push<bool>(
context,
CupertinoPageRoute(
builder: (context) => CartonPackageEditor(carton: _carton)),
);
bool? updated = false;
if (_carton.cartonType == mix_carton) {
updated = await Navigator.push<bool>(
context,
CupertinoPageRoute(
builder: (context) => MixCartonEditor(carton: _carton)),
);
}
if (_carton.cartonType == carton_from_packages) {
updated = await Navigator.push<bool>(
context,
CupertinoPageRoute(
builder: (context) => CartonPackageEditor(carton: _carton)),
);
}
if (updated ?? false) {
Carton? c =
@@ -489,9 +518,8 @@ class _CartonInfoState extends State<CartonInfo> {
_isLoading = true;
});
try {
// var cartonModel = Provider.of<CartonModel>(context, listen: false);
// await cartonModel.deleteCarton(widget.carton);
// Navigator.pop(context, true);
await context.read<CartonModel>().deleteCarton(widget.carton);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {