add submit widget for mix carton
This commit is contained in:
375
lib/pages/carton/carton_size_widget.dart
Normal file
375
lib/pages/carton/carton_size_widget.dart
Normal file
@@ -0,0 +1,375 @@
|
||||
import 'package:fcs/pages/widgets/local_radio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../domain/constants.dart';
|
||||
import '../../../domain/entities/carton_size.dart';
|
||||
import '../../../domain/entities/fcs_shipment.dart';
|
||||
import '../../../helpers/theme.dart';
|
||||
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';
|
||||
import '../widgets/local_text.dart';
|
||||
import '../widgets/local_title.dart';
|
||||
import '../widgets/previous_button.dart';
|
||||
|
||||
typedef OnPrevious = Function();
|
||||
|
||||
typedef OnContinue = Function(FcsShipment shipment, String cartonSizeType,
|
||||
{CartonSize? standardSize, double? length, double? width, double? height});
|
||||
|
||||
class CartonSizeWidget extends StatefulWidget {
|
||||
final OnPrevious? onPrevious;
|
||||
final OnContinue? onContinue;
|
||||
final User sender;
|
||||
final User consignee;
|
||||
final FcsShipment? shipment;
|
||||
final String cartonSizeType;
|
||||
final CartonSize? standardSize;
|
||||
final double? length;
|
||||
final double? width;
|
||||
final double? height;
|
||||
|
||||
const CartonSizeWidget(
|
||||
{Key? key,
|
||||
this.onPrevious,
|
||||
this.onContinue,
|
||||
this.shipment,
|
||||
required this.cartonSizeType,
|
||||
this.standardSize,
|
||||
this.length,
|
||||
this.width,
|
||||
this.height,
|
||||
required this.sender,
|
||||
required this.consignee})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
State<CartonSizeWidget> createState() => _CartonSizeWidgetState();
|
||||
}
|
||||
|
||||
class _CartonSizeWidgetState extends State<CartonSizeWidget> {
|
||||
FcsShipment? _shipment;
|
||||
String _cartionSizeType = standardCarton;
|
||||
|
||||
List<FcsShipment> _shipments = [];
|
||||
CartonSize? _selectStandardSize;
|
||||
|
||||
TextEditingController _widthController = new TextEditingController();
|
||||
TextEditingController _heightController = new TextEditingController();
|
||||
TextEditingController _lengthController = new TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_init();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
_init() async {
|
||||
_shipment = widget.shipment;
|
||||
_cartionSizeType = widget.cartonSizeType;
|
||||
|
||||
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();
|
||||
|
||||
var fcsShipments =
|
||||
await context.read<FcsShipmentModel>().getActiveFcsShipments();
|
||||
_shipments = fcsShipments;
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<CartonSize> cartonSizes = context.watch<CartonSizeModel>().cartonSizes;
|
||||
bool isStandardSize = _cartionSizeType == standardCarton;
|
||||
bool isCustomSize = _cartionSizeType == customCarton;
|
||||
bool isNoneDefinedSize = _cartionSizeType == packageCartion;
|
||||
|
||||
final senderBox = DisplayText(
|
||||
text: widget.sender.name,
|
||||
labelTextKey: "box.sender.title",
|
||||
iconData: MaterialCommunityIcons.account_arrow_right,
|
||||
);
|
||||
|
||||
final consigneeBox = DisplayText(
|
||||
text: widget.consignee.name,
|
||||
labelTextKey: "box.consignee.title",
|
||||
iconData: MaterialCommunityIcons.account_arrow_left,
|
||||
);
|
||||
|
||||
final userRow = Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: senderBox,
|
||||
flex: 2,
|
||||
),
|
||||
Flexible(child: consigneeBox)
|
||||
],
|
||||
);
|
||||
|
||||
final continueBtn = ContinueButton(onTap: () {
|
||||
double l = double.tryParse(_lengthController.text) ?? 0;
|
||||
double w = double.tryParse(_widthController.text) ?? 0;
|
||||
double h = double.tryParse(_heightController.text) ?? 0;
|
||||
|
||||
if (_shipment == null) {
|
||||
showMsgDialog(context, "Error", "Please select shipment");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isStandardSize &&
|
||||
_selectStandardSize == null &&
|
||||
!isCustomSize &&
|
||||
!isNoneDefinedSize) {
|
||||
showMsgDialog(
|
||||
context, "Error", "Please select the standard cartion size");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isCustomSize &&
|
||||
!isStandardSize &&
|
||||
!isNoneDefinedSize &&
|
||||
(l == 0 || w == 0 || h == 0)) {
|
||||
showMsgDialog(context, "Error", "Please add the cartion size");
|
||||
return;
|
||||
}
|
||||
|
||||
if (widget.onContinue != null) {
|
||||
widget.onContinue!(_shipment!, _cartionSizeType,
|
||||
standardSize: _selectStandardSize, length: l, width: w, height: h);
|
||||
}
|
||||
});
|
||||
|
||||
final previousBtn = PreviousButton(onTap: () {
|
||||
if (widget.onPrevious != null) {
|
||||
widget.onPrevious!();
|
||||
}
|
||||
});
|
||||
|
||||
final standardSizeBox = Padding(
|
||||
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(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
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)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final cartonSizedBox = Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// standard carton size
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_cartionSizeType = standardCarton;
|
||||
});
|
||||
},
|
||||
child: Row(children: <Widget>[
|
||||
LocalRadio(
|
||||
value: standardCarton,
|
||||
groupValue: _cartionSizeType,
|
||||
onChanged: (p0) {
|
||||
setState(() {
|
||||
_cartionSizeType = standardCarton;
|
||||
});
|
||||
},
|
||||
),
|
||||
Flexible(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
child: LocalText(context, 'box.standard_carton_size',
|
||||
fontSize: 15,
|
||||
color: isStandardSize ? primaryColor : labelColor),
|
||||
),
|
||||
)
|
||||
]),
|
||||
),
|
||||
standardSizeBox,
|
||||
const SizedBox(height: 20),
|
||||
// custom size
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_cartionSizeType = customCarton;
|
||||
});
|
||||
},
|
||||
child: Row(children: <Widget>[
|
||||
LocalRadio(
|
||||
value: customCarton,
|
||||
groupValue: _cartionSizeType,
|
||||
onChanged: (p0) {
|
||||
setState(() {
|
||||
_cartionSizeType = customCarton;
|
||||
});
|
||||
},
|
||||
),
|
||||
Flexible(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
child: LocalText(context, 'box.custom_size',
|
||||
fontSize: 15,
|
||||
color: isCustomSize ? primaryColor : Colors.black54),
|
||||
),
|
||||
)
|
||||
]),
|
||||
),
|
||||
customSizeBox,
|
||||
const SizedBox(height: 10),
|
||||
// not defined size
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_cartionSizeType = packageCartion;
|
||||
});
|
||||
},
|
||||
child: Row(children: <Widget>[
|
||||
LocalRadio(
|
||||
value: packageCartion,
|
||||
groupValue: _cartionSizeType,
|
||||
onChanged: (p0) {
|
||||
setState(() {
|
||||
_cartionSizeType = packageCartion;
|
||||
});
|
||||
},
|
||||
),
|
||||
Flexible(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
child: LocalText(context, 'box.package_size',
|
||||
fontSize: 15,
|
||||
color: isNoneDefinedSize ? primaryColor : Colors.black54),
|
||||
),
|
||||
)
|
||||
]),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 34.0),
|
||||
child: Text(
|
||||
"No defined size",
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: isNoneDefinedSize ? Colors.black : labelColor),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
|
||||
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,
|
||||
values: _shipments,
|
||||
));
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView(
|
||||
padding: EdgeInsets.only(left: 10, right: 10),
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
userRow,
|
||||
LocalTitle(textKey: "box.select_carton_size"),
|
||||
const SizedBox(height: 8),
|
||||
cartonSizedBox,
|
||||
const SizedBox(height: 8),
|
||||
LocalTitle(textKey: "box.select_shipment"),
|
||||
const SizedBox(height: 5),
|
||||
fcsShipmentsBox
|
||||
],
|
||||
)),
|
||||
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,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user