Files
fcs/lib/pages/carton/carton_size_widget.dart

481 lines
14 KiB
Dart
Raw Normal View History

2024-02-02 18:00:51 +06:30
import 'package:fcs/pages/widgets/local_radio.dart';
2024-02-01 18:07:40 +06:30
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:provider/provider.dart';
2024-02-02 18:00:51 +06:30
import '../../../domain/constants.dart';
import '../../../domain/entities/carton_size.dart';
2024-02-01 18:07:40 +06:30
import '../../../domain/entities/fcs_shipment.dart';
import '../../../helpers/theme.dart';
2024-02-05 11:13:12 +06:30
import '../../domain/entities/user.dart';
import '../carton_size/model/carton_size_model.dart';
import '../fcs_shipment/model/fcs_shipment_model.dart';
import '../main/util.dart';
import '../widgets/box_size_picker.dart';
import '../widgets/continue_button.dart';
import '../widgets/display_text.dart';
import '../widgets/local_dropdown.dart';
2024-02-05 17:49:12 +06:30
import '../widgets/local_radio_buttons.dart';
2024-02-05 11:13:12 +06:30
import '../widgets/local_text.dart';
import '../widgets/local_title.dart';
import '../widgets/previous_button.dart';
2024-02-01 18:07:40 +06:30
typedef OnPrevious = Function();
2024-02-09 12:16:39 +06:30
typedef OnContinue = Function(String deliveryType, String billType,
FcsShipment shipment, String cartonSizeType,
2024-02-02 18:00:51 +06:30
{CartonSize? standardSize, double? length, double? width, double? height});
2024-02-05 11:13:12 +06:30
class CartonSizeWidget extends StatefulWidget {
2024-02-01 18:07:40 +06:30
final OnPrevious? onPrevious;
2024-02-02 18:00:51 +06:30
final OnContinue? onContinue;
2024-02-05 11:13:12 +06:30
final User sender;
final User consignee;
2024-02-05 17:49:12 +06:30
final String deliveryType;
2024-02-09 12:16:39 +06:30
final String billType;
2024-02-02 18:00:51 +06:30
final FcsShipment? shipment;
final String cartonSizeType;
final CartonSize? standardSize;
final double? length;
final double? width;
final double? height;
2024-02-05 11:13:12 +06:30
const CartonSizeWidget(
2024-02-01 18:07:40 +06:30
{Key? key,
this.onPrevious,
2024-02-02 18:00:51 +06:30
this.onContinue,
this.shipment,
required this.cartonSizeType,
this.standardSize,
this.length,
this.width,
2024-02-05 11:13:12 +06:30
this.height,
required this.sender,
2024-02-05 17:49:12 +06:30
required this.consignee,
2024-02-09 12:16:39 +06:30
required this.deliveryType,
required this.billType})
2024-02-01 18:07:40 +06:30
: super(key: key);
@override
2024-02-05 11:13:12 +06:30
State<CartonSizeWidget> createState() => _CartonSizeWidgetState();
2024-02-01 18:07:40 +06:30
}
2024-02-05 11:13:12 +06:30
class _CartonSizeWidgetState extends State<CartonSizeWidget> {
2024-02-05 17:49:12 +06:30
List<String> _deliveryTypes = [delivery_caton, pickup_carton];
2024-02-01 18:07:40 +06:30
FcsShipment? _shipment;
2024-02-09 17:10:19 +06:30
String _cartonSizeType = standardCarton;
2024-02-02 18:00:51 +06:30
List<FcsShipment> _shipments = [];
CartonSize? _selectStandardSize;
2024-02-05 17:49:12 +06:30
late String _selectedDeliveryType;
2024-02-09 12:16:39 +06:30
late String _billToValue;
2024-02-02 18:00:51 +06:30
TextEditingController _widthController = new TextEditingController();
TextEditingController _heightController = new TextEditingController();
TextEditingController _lengthController = new TextEditingController();
2024-02-01 18:07:40 +06:30
@override
void initState() {
_init();
super.initState();
}
_init() async {
2024-02-05 17:49:12 +06:30
_selectedDeliveryType = widget.deliveryType;
2024-02-09 12:16:39 +06:30
_billToValue = widget.billType;
2024-02-09 17:10:19 +06:30
_cartonSizeType = widget.cartonSizeType;
2024-02-09 12:16:39 +06:30
2024-02-02 18:00:51 +06:30
List<CartonSize> cartonSizes = context.read<CartonSizeModel>().cartonSizes;
_selectStandardSize = widget.standardSize ?? cartonSizes.first;
_lengthController.text =
2024-02-09 17:10:19 +06:30
widget.length == null ? "0" : removeTrailingZeros(widget.length ?? 0);
2024-02-02 18:00:51 +06:30
_widthController.text =
2024-02-09 17:10:19 +06:30
widget.width == null ? "0" : removeTrailingZeros(widget.width ?? 0);
2024-02-02 18:00:51 +06:30
_heightController.text =
2024-02-09 17:10:19 +06:30
widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0);
2024-02-02 18:00:51 +06:30
2024-02-01 18:07:40 +06:30
var fcsShipments =
await context.read<FcsShipmentModel>().getActiveFcsShipments();
2024-02-02 18:00:51 +06:30
_shipments = fcsShipments;
2024-02-09 17:10:19 +06:30
_shipment = widget.shipment;
2024-02-01 18:07:40 +06:30
if (mounted) {
setState(() {});
}
}
2024-02-09 17:10:19 +06:30
@override
void didUpdateWidget(covariant CartonSizeWidget oldWidget) {
_init();
super.didUpdateWidget(oldWidget);
}
2024-02-01 18:07:40 +06:30
@override
Widget build(BuildContext context) {
2024-02-02 18:00:51 +06:30
List<CartonSize> cartonSizes = context.watch<CartonSizeModel>().cartonSizes;
2024-02-09 17:10:19 +06:30
bool isStandardSize = _cartonSizeType == standardCarton;
bool isCustomSize = _cartonSizeType == customCarton;
bool isNoneDefinedSize = _cartonSizeType == packageCartion;
2024-02-02 18:00:51 +06:30
2024-02-05 11:13:12 +06:30
final senderBox = DisplayText(
text: widget.sender.name,
labelTextKey: "box.sender.title",
iconData: MaterialCommunityIcons.account_arrow_right,
2024-02-05 17:49:12 +06:30
subText: Text(widget.sender.fcsID!,
style: TextStyle(fontSize: 13, color: labelColor)),
2024-02-05 11:13:12 +06:30
);
final consigneeBox = DisplayText(
text: widget.consignee.name,
labelTextKey: "box.consignee.title",
iconData: MaterialCommunityIcons.account_arrow_left,
2024-02-05 17:49:12 +06:30
subText: Text(widget.consignee.fcsID!,
style: TextStyle(fontSize: 13, color: labelColor)),
2024-02-05 11:13:12 +06:30
);
final userRow = Row(
children: [
2024-02-05 17:49:12 +06:30
Expanded(
2024-02-05 11:13:12 +06:30
child: senderBox,
flex: 2,
),
Flexible(child: consigneeBox)
],
);
2024-02-05 17:49:12 +06:30
final deliveryTypeBox = LocalRadioButtons(
values: _deliveryTypes,
selectedValue: _selectedDeliveryType,
callback: (String? v) {
setState(() {
_selectedDeliveryType = v!;
});
});
2024-02-09 12:16:39 +06:30
final billRadioBox = Container(
child: Row(
children: [
Flexible(
child: InkWell(
onTap: () {
setState(() {
_billToValue = billToSender;
});
},
child: Row(children: <Widget>[
LocalRadio(
value: billToSender,
groupValue: _billToValue,
onChanged: (p0) {
setState(() {
_billToValue = billToSender;
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.bill_to_sender',
fontSize: 15,
color: _billToValue == billToSender
? primaryColor
: Colors.black),
),
)
]),
)),
Flexible(
child: InkWell(
onTap: () {
setState(() {
_billToValue = billToConsignee;
});
},
child: Row(children: <Widget>[
LocalRadio(
value: billToConsignee,
groupValue: _billToValue,
onChanged: (p0) {
setState(() {
_billToValue = billToConsignee;
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.bill_to.consignee',
fontSize: 15,
color: _billToValue == billToConsignee
? primaryColor
: Colors.black),
),
)
]),
),
)
],
),
);
2024-02-01 18:07:40 +06:30
final continueBtn = ContinueButton(onTap: () {
2024-02-02 18:00:51 +06:30
double l = double.tryParse(_lengthController.text) ?? 0;
double w = double.tryParse(_widthController.text) ?? 0;
double h = double.tryParse(_heightController.text) ?? 0;
2024-02-01 18:07:40 +06:30
if (_shipment == null) {
showMsgDialog(context, "Error", "Please select shipment");
return;
}
2024-02-02 18:00:51 +06:30
if (isStandardSize &&
_selectStandardSize == null &&
!isCustomSize &&
!isNoneDefinedSize) {
showMsgDialog(
2024-02-05 17:49:12 +06:30
context, "Error", "Please select the standard carton size");
2024-02-02 18:00:51 +06:30
return;
}
if (isCustomSize &&
!isStandardSize &&
!isNoneDefinedSize &&
(l == 0 || w == 0 || h == 0)) {
2024-02-05 17:49:12 +06:30
showMsgDialog(context, "Error", "Please add the carton size");
2024-02-02 18:00:51 +06:30
return;
}
if (widget.onContinue != null) {
2024-02-09 12:16:39 +06:30
widget.onContinue!(
2024-02-09 17:10:19 +06:30
_selectedDeliveryType, _billToValue, _shipment!, _cartonSizeType,
2024-02-02 18:00:51 +06:30
standardSize: _selectStandardSize, length: l, width: w, height: h);
}
2024-02-01 18:07:40 +06:30
});
final previousBtn = PreviousButton(onTap: () {
if (widget.onPrevious != null) {
widget.onPrevious!();
}
});
final standardSizeBox = Padding(
2024-02-02 18:00:51 +06:30
padding: const EdgeInsets.only(left: 34.0, top: 8),
child: IgnorePointer(
ignoring: !isStandardSize,
child: DropdownButton<CartonSize>(
isDense: true,
value: _selectStandardSize,
style: TextStyle(color: Colors.black, fontSize: 14),
underline: Container(height: 1, color: Colors.grey),
onChanged: (newValue) {
setState(() {
_selectStandardSize = newValue!;
});
},
isExpanded: true,
items:
cartonSizes.map<DropdownMenuItem<CartonSize>>((CartonSize value) {
return DropdownMenuItem<CartonSize>(
value: value,
child: Row(
children: [
Text("${value.name} - ",
style: TextStyle(
color: isStandardSize ? Colors.black : labelColor)),
Text(
"${value.length.toInt()}”x${value.width.toInt()}”x${value.height.toInt()}",
style: TextStyle(color: labelColor)),
],
),
);
}).toList(),
2024-02-01 18:07:40 +06:30
),
2024-02-02 18:00:51 +06:30
),
);
final lengthBox = BoxSizePicker(
lableKey: 'box.length',
controller: _lengthController,
enable: isCustomSize);
final widthBox = BoxSizePicker(
lableKey: 'box.width',
controller: _widthController,
enable: isCustomSize);
final heightBox = BoxSizePicker(
lableKey: 'box.height',
controller: _heightController,
enable: isCustomSize);
final customSizeBox = Padding(
padding: const EdgeInsets.only(left: 34.0),
child: Row(
children: [
Flexible(child: lengthBox),
Flexible(child: widthBox),
Flexible(child: heightBox)
],
2024-02-01 18:07:40 +06:30
),
);
final cartonSizedBox = Column(
2024-02-02 18:00:51 +06:30
crossAxisAlignment: CrossAxisAlignment.start,
2024-02-01 18:07:40 +06:30
children: [
// standard carton size
InkWell(
onTap: () {
setState(() {
2024-02-09 17:10:19 +06:30
_cartonSizeType = standardCarton;
2024-02-01 18:07:40 +06:30
});
},
child: Row(children: <Widget>[
2024-02-02 18:00:51 +06:30
LocalRadio(
value: standardCarton,
2024-02-09 17:10:19 +06:30
groupValue: _cartonSizeType,
2024-02-02 18:00:51 +06:30
onChanged: (p0) {
2024-02-01 18:07:40 +06:30
setState(() {
2024-02-09 17:10:19 +06:30
_cartonSizeType = standardCarton;
2024-02-01 18:07:40 +06:30
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.standard_carton_size',
2024-02-02 18:00:51 +06:30
fontSize: 15,
color: isStandardSize ? primaryColor : labelColor),
2024-02-01 18:07:40 +06:30
),
)
]),
),
standardSizeBox,
2024-02-02 18:00:51 +06:30
const SizedBox(height: 20),
2024-02-01 18:07:40 +06:30
// custom size
InkWell(
onTap: () {
setState(() {
2024-02-09 17:10:19 +06:30
_cartonSizeType = customCarton;
2024-02-01 18:07:40 +06:30
});
},
child: Row(children: <Widget>[
2024-02-02 18:00:51 +06:30
LocalRadio(
value: customCarton,
2024-02-09 17:10:19 +06:30
groupValue: _cartonSizeType,
2024-02-02 18:00:51 +06:30
onChanged: (p0) {
2024-02-01 18:07:40 +06:30
setState(() {
2024-02-09 17:10:19 +06:30
_cartonSizeType = customCarton;
2024-02-01 18:07:40 +06:30
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.custom_size',
2024-02-02 18:00:51 +06:30
fontSize: 15,
color: isCustomSize ? primaryColor : Colors.black54),
2024-02-01 18:07:40 +06:30
),
)
]),
),
2024-02-02 18:00:51 +06:30
customSizeBox,
const SizedBox(height: 10),
2024-02-01 18:07:40 +06:30
// not defined size
InkWell(
onTap: () {
setState(() {
2024-02-09 17:10:19 +06:30
_cartonSizeType = packageCartion;
2024-02-01 18:07:40 +06:30
});
},
child: Row(children: <Widget>[
2024-02-02 18:00:51 +06:30
LocalRadio(
value: packageCartion,
2024-02-09 17:10:19 +06:30
groupValue: _cartonSizeType,
2024-02-02 18:00:51 +06:30
onChanged: (p0) {
2024-02-01 18:07:40 +06:30
setState(() {
2024-02-09 17:10:19 +06:30
_cartonSizeType = packageCartion;
2024-02-01 18:07:40 +06:30
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.package_size',
2024-02-02 18:00:51 +06:30
fontSize: 15,
color: isNoneDefinedSize ? primaryColor : Colors.black54),
2024-02-01 18:07:40 +06:30
),
)
]),
),
2024-02-02 18:00:51 +06:30
Padding(
padding: const EdgeInsets.only(left: 34.0),
child: Text(
"No defined size",
style: TextStyle(
fontSize: 14,
color: isNoneDefinedSize ? Colors.black : labelColor),
),
)
2024-02-01 18:07:40 +06:30
],
);
final fcsShipmentsBox = Container(
padding: EdgeInsets.only(top: 10),
child: LocalDropdown<FcsShipment>(
callback: (v) {
setState(() {
_shipment = v;
});
},
labelKey: "box.shipment",
iconData: Ionicons.ios_airplane,
display: (u) => u.shipmentNumber,
selectedValue: _shipment,
2024-02-02 18:00:51 +06:30
values: _shipments,
2024-02-01 18:07:40 +06:30
));
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: ListView(
padding: EdgeInsets.only(left: 10, right: 10),
children: [
2024-02-02 18:00:51 +06:30
const SizedBox(height: 8),
2024-02-05 11:13:12 +06:30
userRow,
2024-02-09 12:16:39 +06:30
const SizedBox(height: 5),
billRadioBox,
LocalTitle(textKey: "box.select.delivery"),
2024-02-05 17:49:12 +06:30
const SizedBox(height: 5),
deliveryTypeBox,
const SizedBox(height: 5),
2024-02-01 18:07:40 +06:30
LocalTitle(textKey: "box.select_carton_size"),
2024-02-02 18:00:51 +06:30
const SizedBox(height: 8),
2024-02-01 18:07:40 +06:30
cartonSizedBox,
2024-02-02 18:00:51 +06:30
const SizedBox(height: 8),
2024-02-01 18:07:40 +06:30
LocalTitle(textKey: "box.select_shipment"),
2024-02-02 18:00:51 +06:30
const SizedBox(height: 5),
2024-02-05 17:49:12 +06:30
fcsShipmentsBox,
const SizedBox(height: 30)
2024-02-01 18:07:40 +06:30
],
)),
Padding(
padding: const EdgeInsets.only(left: 15, right: 15),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
widget.onPrevious == null ? const SizedBox() : previousBtn,
continueBtn
// warehouse != null ? continueBtn : const SizedBox(),
],
),
),
const SizedBox(
height: 20,
),
],
);
}
}