481 lines
17 KiB
Dart
481 lines
17 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
import '../../constants.dart';
|
|
import '../../../domain/entities/cargo_type.dart';
|
|
import '../../../domain/entities/carton_size.dart';
|
|
import '../../../domain/entities/fcs_shipment.dart';
|
|
import '../../../helpers/theme.dart';
|
|
import '../../domain/entities/user.dart';
|
|
import '../main/util.dart';
|
|
import '../widgets/local_text.dart';
|
|
import '../widgets/previous_button.dart';
|
|
import '../widgets/submit_text_widget.dart';
|
|
|
|
typedef OnCreateCarton = Function();
|
|
typedef OnPrevious = Function();
|
|
final NumberFormat numberFormatter = NumberFormat("#,###");
|
|
|
|
class CartonSubmit extends StatelessWidget {
|
|
final User sender;
|
|
final User consingee;
|
|
final String billToValue;
|
|
final FcsShipment shipment;
|
|
// final List<Package> packages;
|
|
final String cartonSizeType;
|
|
final CartonSize? standardSize;
|
|
final double length;
|
|
final double width;
|
|
final double height;
|
|
final String lastMile;
|
|
final List<CargoType> cargoTypes;
|
|
final List<CargoType> surchareItems;
|
|
final OnCreateCarton? onCreate;
|
|
final OnPrevious? onPrevious;
|
|
final bool isNew;
|
|
const CartonSubmit(
|
|
{super.key,
|
|
required this.sender,
|
|
required this.consingee,
|
|
required this.billToValue,
|
|
this.onCreate,
|
|
this.onPrevious,
|
|
required this.shipment,
|
|
// this.packages = const [],
|
|
this.standardSize,
|
|
required this.cartonSizeType,
|
|
required this.lastMile,
|
|
this.length = 0,
|
|
this.width = 0,
|
|
this.height = 0,
|
|
this.cargoTypes = const [],
|
|
this.surchareItems = const [],
|
|
this.isNew = true});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
String? boxDimension = cartonSizeType == standardCarton
|
|
? "${standardSize?.name} - ${standardSize?.length.toInt()}”x${standardSize?.width.toInt()}”x${standardSize?.height.toInt()}”"
|
|
: cartonSizeType == customCarton
|
|
? "${length.toInt()}”x${width.toInt()}”x${height.toInt()}”"
|
|
: null;
|
|
|
|
double totalWeight = cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
|
|
|
final cartonType = Padding(
|
|
padding: const EdgeInsets.only(top: 10),
|
|
child: SubmitTextWidget(
|
|
labelKey: 'box.carton.type', text: carton_from_packages),
|
|
);
|
|
|
|
final shipmentBox = Padding(
|
|
padding: const EdgeInsets.only(top: 10),
|
|
child: SubmitTextWidget(
|
|
labelKey: 'box.shipment',
|
|
text: shipment.shipmentNumber ?? '',
|
|
subText: shipment.status ?? "",
|
|
),
|
|
);
|
|
|
|
final usersBox = Padding(
|
|
padding: const EdgeInsets.only(top: 10),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 5, bottom: 5),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: LocalText(context, 'box.consignee.title',
|
|
color: primaryColor,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.normal),
|
|
),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 13),
|
|
child: LocalText(context, 'box.sender.title',
|
|
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: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Expanded(
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(consingee.name ?? "",
|
|
style: const TextStyle(
|
|
fontSize: 16.0, fontWeight: FontWeight.w500)),
|
|
consingee.fcsID == null
|
|
? const SizedBox()
|
|
: Text(consingee.fcsID!,
|
|
style: const TextStyle(
|
|
fontSize: 14.0, color: Colors.grey)),
|
|
],
|
|
),
|
|
),
|
|
// billToValue == billToConsignee
|
|
// ? billWidget(context)
|
|
// : const SizedBox()
|
|
],
|
|
)),
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 15),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(sender.name ?? "",
|
|
style: const TextStyle(
|
|
fontSize: 16.0,
|
|
fontWeight: FontWeight.w500)),
|
|
sender.fcsID == null
|
|
? const SizedBox()
|
|
: Text(sender.fcsID!,
|
|
style: const TextStyle(
|
|
fontSize: 14.0, color: Colors.grey)),
|
|
],
|
|
),
|
|
),
|
|
// billToValue == billToSender
|
|
// ? billWidget(context)
|
|
// : const SizedBox()
|
|
],
|
|
),
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
),
|
|
]),
|
|
);
|
|
|
|
final billToBox = Padding(
|
|
padding: const EdgeInsets.only(top: 10),
|
|
child: SubmitTextWidget(
|
|
labelKey: 'box.bill_to',
|
|
text: billToValue == billToSender ? 'Sender' : 'Consignee',
|
|
),
|
|
);
|
|
|
|
final deliveryTypeBox = Padding(
|
|
padding: const EdgeInsets.only(top: 10),
|
|
child: SubmitTextWidget(
|
|
labelKey: 'box.select.delivery',
|
|
text: lastMile == delivery_caton ? 'Delivery' : 'Pick-up',
|
|
),
|
|
);
|
|
|
|
final cartonSizeBox = Padding(
|
|
padding: const EdgeInsets.only(top: 10),
|
|
child: SubmitTextWidget(
|
|
labelKey: 'box.select_carton_size',
|
|
text: boxDimension ?? 'No defined size',
|
|
),
|
|
);
|
|
|
|
// final packagesBox = Padding(
|
|
// padding: const EdgeInsets.only(top: 10),
|
|
// child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
|
// Padding(
|
|
// padding: const EdgeInsets.only(left: 5, bottom: 5),
|
|
// child: LocalText(context, 'box.package.count',
|
|
// translationVariables: [packages.length.toString()],
|
|
// 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: Wrap(
|
|
// spacing: 15,
|
|
// children: packages.map((e) {
|
|
// return SizedBox(
|
|
// width: MediaQuery.of(context).size.width / 2.5,
|
|
// child: Padding(
|
|
// padding: const EdgeInsets.symmetric(vertical: 3),
|
|
// child: Text(
|
|
// e.trackingID ?? "",
|
|
// style: TextStyle(color: Colors.black, fontSize: 15),
|
|
// ),
|
|
// ),
|
|
// );
|
|
// }).toList()),
|
|
// ),
|
|
// ),
|
|
// ]),
|
|
// );
|
|
|
|
final cargosBox = 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.cargo.type',
|
|
color: primaryColor,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.normal),
|
|
Text(
|
|
"${twoDecimalFormatted(double.tryParse(removeTrailingZeros(totalWeight)) ?? 0)} lb",
|
|
style: TextStyle(color: Colors.black, fontSize: 15))
|
|
],
|
|
),
|
|
),
|
|
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: cargoTypes.map((e) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 3),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
e.name ?? "",
|
|
style: TextStyle(
|
|
color: Colors.black, fontSize: 15),
|
|
),
|
|
Text(
|
|
"${twoDecimalFormatted(double.tryParse(removeTrailingZeros(e.weight)) ?? 0)} lb",
|
|
style: TextStyle(
|
|
color: Colors.black, fontSize: 15))
|
|
],
|
|
),
|
|
e.isMixCargo
|
|
? Padding(
|
|
padding: const EdgeInsets.only(left: 20),
|
|
child: Column(
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment.start,
|
|
children: e.mixCargoes.map((c) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
vertical: 2),
|
|
child: Text(
|
|
"- ${c.name}",
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
color: labelColor),
|
|
),
|
|
);
|
|
}).toList()),
|
|
)
|
|
: const SizedBox()
|
|
],
|
|
),
|
|
);
|
|
}).toList()),
|
|
// const SizedBox(height: 10),
|
|
// Column(
|
|
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
// children: surchareItems.map((e) {
|
|
// return Padding(
|
|
// padding: const EdgeInsets.symmetric(vertical: 3),
|
|
// child: Row(
|
|
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
// children: [
|
|
// Text(
|
|
// e.name ?? "",
|
|
// style: TextStyle(color: labelColor, fontSize: 15),
|
|
// ),
|
|
// Text("${numberFormatter.format(e.qty)} 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: surchareItems.map((e) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 3),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
e.name ?? "",
|
|
style: TextStyle(
|
|
color: Colors.black, fontSize: 15),
|
|
),
|
|
Text(
|
|
"${removeTrailingZeros((e.qty).toDouble())} pc",
|
|
textAlign: TextAlign.end,
|
|
style: TextStyle(
|
|
color: Colors.black, fontSize: 15))
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}).toList()),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
]),
|
|
);
|
|
|
|
final createBtn = InkWell(
|
|
onTap: () {
|
|
if (onCreate != null) {
|
|
onCreate!();
|
|
}
|
|
},
|
|
child: Container(
|
|
alignment: Alignment.bottomRight,
|
|
height: 45,
|
|
width: 150,
|
|
decoration: BoxDecoration(
|
|
color: primaryColor,
|
|
borderRadius: BorderRadius.circular(5),
|
|
),
|
|
child: TextButton(
|
|
onPressed: null,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Flexible(
|
|
child: LocalText(
|
|
context, isNew ? 'box.crete.carton' : "box.update.btn",
|
|
color: Colors.white, fontSize: 15),
|
|
),
|
|
const SizedBox(width: 5),
|
|
const Icon(
|
|
MaterialCommunityIcons.check_circle_outline,
|
|
color: Colors.white,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
));
|
|
|
|
final previousBtn = PreviousButton(onTap: () {
|
|
if (onPrevious != null) {
|
|
onPrevious!();
|
|
}
|
|
});
|
|
|
|
return Column(
|
|
children: [
|
|
Expanded(
|
|
child: ListView(
|
|
padding:
|
|
const EdgeInsets.only(left: 20, right: 20, top: 8, bottom: 20),
|
|
children: [
|
|
cartonType,
|
|
const SizedBox(height: 10),
|
|
usersBox,
|
|
const SizedBox(height: 10),
|
|
billToBox,
|
|
const SizedBox(height: 10),
|
|
deliveryTypeBox,
|
|
const SizedBox(height: 10),
|
|
cartonSizeBox,
|
|
const SizedBox(height: 10),
|
|
shipmentBox,
|
|
const SizedBox(height: 10),
|
|
// packages.isNotEmpty ? packagesBox : const SizedBox(),
|
|
// const SizedBox(height: 10),
|
|
cargoTypes.isNotEmpty ? cargosBox : const SizedBox(),
|
|
const SizedBox(height: 10),
|
|
surchareItems.isNotEmpty ? surChargeItemsBox : const SizedBox(),
|
|
const SizedBox(height: 20),
|
|
],
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 15, right: 15),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [previousBtn, createBtn],
|
|
),
|
|
),
|
|
const SizedBox(height: 20)
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget billWidget(BuildContext context) {
|
|
return Row(
|
|
children: [
|
|
Icon(Ionicons.document_text_outline, color: primaryColor, size: 20),
|
|
Text("Bill to", style: TextStyle(color: primaryColor, fontSize: 15))
|
|
],
|
|
);
|
|
}
|
|
}
|