add submit widget for mix carton
This commit is contained in:
289
lib/pages/carton/mix_carton/mix_carton_submit.dart
Normal file
289
lib/pages/carton/mix_carton/mix_carton_submit.dart
Normal file
@@ -0,0 +1,289 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../domain/constants.dart';
|
||||
import '../../../domain/entities/cargo_type.dart';
|
||||
import '../../../domain/entities/carton.dart';
|
||||
import '../../../domain/entities/carton_size.dart';
|
||||
import '../../../domain/entities/fcs_shipment.dart';
|
||||
import '../../../helpers/theme.dart';
|
||||
import '../../widgets/local_text.dart';
|
||||
import '../../widgets/previous_button.dart';
|
||||
import '../../widgets/submit_text_widget.dart';
|
||||
import "package:collection/collection.dart";
|
||||
|
||||
typedef OnCreateMixCarton = Function();
|
||||
typedef OnPrevious = Function();
|
||||
|
||||
class MixCartonSubmit extends StatefulWidget {
|
||||
final FcsShipment shipment;
|
||||
final List<Carton> cartons;
|
||||
final String cartonSizeType;
|
||||
final CartonSize? standardSize;
|
||||
final double length;
|
||||
final double width;
|
||||
final double height;
|
||||
final OnCreateMixCarton? onCreate;
|
||||
final OnPrevious? onPrevious;
|
||||
const MixCartonSubmit(
|
||||
{Key? key,
|
||||
this.onCreate,
|
||||
this.onPrevious,
|
||||
required this.shipment,
|
||||
this.cartons = const [],
|
||||
this.standardSize,
|
||||
required this.cartonSizeType,
|
||||
this.length = 0,
|
||||
this.width = 0,
|
||||
this.height = 0})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
State<MixCartonSubmit> createState() => _MixCartonSubmitState();
|
||||
}
|
||||
|
||||
class _MixCartonSubmitState extends State<MixCartonSubmit> {
|
||||
final NumberFormat numberFormatter = NumberFormat("#,###");
|
||||
Map<String?, double> _mapCargosByWeight = {};
|
||||
Map<String?, double> _mapCargosByCustomDutyFee = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_init();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
_init() {
|
||||
List<CargoType> _cargoTypes = [];
|
||||
for (var c in widget.cartons) {
|
||||
_cargoTypes.addAll(c.cargoTypes);
|
||||
}
|
||||
|
||||
// get cargos by weight
|
||||
Map<String?, List<CargoType>> _cargosByWeight =
|
||||
groupCargos(_cargoTypes.where((e) => !e.isCutomDuty).toList());
|
||||
|
||||
_cargosByWeight.forEach((key, value) {
|
||||
double total = value.fold(0, (sum, item) => sum + item.weight);
|
||||
_mapCargosByWeight[key] = total;
|
||||
});
|
||||
|
||||
// get cargos by custom duty fee
|
||||
Map<String?, List<CargoType>> _cargosByCustomDutyFee =
|
||||
groupCargos(_cargoTypes.where((e) => e.isCutomDuty).toList());
|
||||
|
||||
_cargosByCustomDutyFee.forEach((key, value) {
|
||||
double total = value.fold(0, (sum, item) => sum + item.qty);
|
||||
_mapCargosByCustomDutyFee[key] = total;
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
Map<String?, List<CargoType>> groupCargos(List<CargoType> cargos) {
|
||||
var groups = groupBy(cargos, (CargoType e) {
|
||||
String? _categoryName = e.name;
|
||||
return _categoryName;
|
||||
});
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String? boxDimension = widget.cartonSizeType == standardCarton
|
||||
? "${widget.standardSize?.name} - ${widget.standardSize?.length.toInt()}”x${widget.standardSize?.width.toInt()}”x${widget.standardSize?.height.toInt()}”"
|
||||
: widget.cartonSizeType == customCarton
|
||||
? "${widget.length.toInt()}”x${widget.width.toInt()}”x${widget.height.toInt()}”"
|
||||
: null;
|
||||
|
||||
final cartonType = Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: SubmitTextWidget(
|
||||
labelKey: 'box.carton.type',
|
||||
text: 'Mix Carton',
|
||||
subText: boxDimension,
|
||||
),
|
||||
);
|
||||
|
||||
final shipmentBox = Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: SubmitTextWidget(
|
||||
labelKey: 'box.shipment',
|
||||
text: widget.shipment.shipmentNumber ?? '',
|
||||
subText: widget.shipment.status ?? "",
|
||||
),
|
||||
);
|
||||
|
||||
final cartonsBox = 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.cartion.count',
|
||||
translationVariables: [widget.cartons.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: widget.cartons.map((e) {
|
||||
return SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 2.5,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Text(
|
||||
e.cartonNumber ?? "",
|
||||
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),
|
||||
child: LocalText(context, 'box.cargo.type',
|
||||
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: _mapCargosByWeight.entries.map((e) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
e.key ?? "",
|
||||
style:
|
||||
TextStyle(color: Colors.black, fontSize: 15),
|
||||
),
|
||||
Text("${numberFormatter.format(e.value)} lb",
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 15))
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
const SizedBox(height: 10),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: _mapCargosByCustomDutyFee.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 createBtn = InkWell(
|
||||
onTap: () {
|
||||
if (widget.onCreate != null) {
|
||||
widget.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, 'box.crete.carton',
|
||||
color: Colors.white, fontSize: 15),
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
const Icon(
|
||||
MaterialCommunityIcons.check_circle_outline,
|
||||
color: Colors.white,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
final previousBtn = PreviousButton(onTap: () {
|
||||
if (widget.onPrevious != null) {
|
||||
widget.onPrevious!();
|
||||
}
|
||||
});
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(20),
|
||||
children: [
|
||||
cartonType,
|
||||
const SizedBox(height: 10),
|
||||
shipmentBox,
|
||||
const SizedBox(height: 10),
|
||||
widget.cartons.isNotEmpty ? cartonsBox : const SizedBox(),
|
||||
const SizedBox(height: 10),
|
||||
cargosBox,
|
||||
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)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user