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-05 17:49:12 +06:30
|
|
|
typedef OnContinue = Function(String deliveryType,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-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,
|
|
|
|
|
required this.deliveryType})
|
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-02 18:00:51 +06:30
|
|
|
String _cartionSizeType = standardCarton;
|
|
|
|
|
|
|
|
|
|
List<FcsShipment> _shipments = [];
|
|
|
|
|
CartonSize? _selectStandardSize;
|
2024-02-05 17:49:12 +06:30
|
|
|
late String _selectedDeliveryType;
|
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-02 18:00:51 +06:30
|
|
|
_shipment = widget.shipment;
|
|
|
|
|
_cartionSizeType = widget.cartonSizeType;
|
2024-02-05 17:49:12 +06:30
|
|
|
|
2024-02-02 18:00:51 +06:30
|
|
|
List<CartonSize> cartonSizes = context.read<CartonSizeModel>().cartonSizes;
|
|
|
|
|
_selectStandardSize = widget.standardSize ?? cartonSizes.first;
|
|
|
|
|
|
|
|
|
|
_lengthController.text =
|
|
|
|
|
widget.length == null ? "0" : widget.length.toString();
|
|
|
|
|
_widthController.text =
|
|
|
|
|
widget.width == null ? "0" : widget.width.toString();
|
|
|
|
|
_heightController.text =
|
|
|
|
|
widget.height == null ? "0" : widget.height.toString();
|
|
|
|
|
|
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-01 18:07:40 +06:30
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-02-02 18:00:51 +06:30
|
|
|
List<CartonSize> cartonSizes = context.watch<CartonSizeModel>().cartonSizes;
|
|
|
|
|
bool isStandardSize = _cartionSizeType == standardCarton;
|
|
|
|
|
bool isCustomSize = _cartionSizeType == customCarton;
|
|
|
|
|
bool isNoneDefinedSize = _cartionSizeType == packageCartion;
|
|
|
|
|
|
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-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-05 17:49:12 +06:30
|
|
|
widget.onContinue!(_selectedDeliveryType,_shipment!, _cartionSizeType,
|
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-02 18:00:51 +06:30
|
|
|
_cartionSizeType = standardCarton;
|
2024-02-01 18:07:40 +06:30
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Row(children: <Widget>[
|
2024-02-02 18:00:51 +06:30
|
|
|
LocalRadio(
|
|
|
|
|
value: standardCarton,
|
|
|
|
|
groupValue: _cartionSizeType,
|
|
|
|
|
onChanged: (p0) {
|
2024-02-01 18:07:40 +06:30
|
|
|
setState(() {
|
2024-02-02 18:00:51 +06:30
|
|
|
_cartionSizeType = 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-02 18:00:51 +06:30
|
|
|
_cartionSizeType = customCarton;
|
2024-02-01 18:07:40 +06:30
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Row(children: <Widget>[
|
2024-02-02 18:00:51 +06:30
|
|
|
LocalRadio(
|
|
|
|
|
value: customCarton,
|
|
|
|
|
groupValue: _cartionSizeType,
|
|
|
|
|
onChanged: (p0) {
|
2024-02-01 18:07:40 +06:30
|
|
|
setState(() {
|
2024-02-02 18:00:51 +06:30
|
|
|
_cartionSizeType = 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-02 18:00:51 +06:30
|
|
|
_cartionSizeType = packageCartion;
|
2024-02-01 18:07:40 +06:30
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Row(children: <Widget>[
|
2024-02-02 18:00:51 +06:30
|
|
|
LocalRadio(
|
|
|
|
|
value: packageCartion,
|
|
|
|
|
groupValue: _cartionSizeType,
|
|
|
|
|
onChanged: (p0) {
|
2024-02-01 18:07:40 +06:30
|
|
|
setState(() {
|
2024-02-02 18:00:51 +06:30
|
|
|
_cartionSizeType = 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-05 17:49:12 +06:30
|
|
|
LocalTitle(textKey: "box.select.delivery", topPadding: 10),
|
|
|
|
|
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,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|