update cargo type form from rate, update carton info and form
This commit is contained in:
@@ -12,6 +12,7 @@ import '../../../domain/entities/carton_size.dart';
|
||||
import '../../../domain/entities/fcs_shipment.dart';
|
||||
import '../../../domain/vo/local_step.dart';
|
||||
import '../../../helpers/theme.dart';
|
||||
import '../../carton_size/model/carton_size_model.dart';
|
||||
import '../../main/util.dart';
|
||||
import '../../widgets/local_text.dart';
|
||||
import '../../widgets/progress.dart';
|
||||
@@ -58,10 +59,30 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
|
||||
|
||||
_init() async {
|
||||
context.read<CartonSelectionModel>().clearSelection();
|
||||
_cartonSizeType = customCarton;
|
||||
_length = widget.carton.length;
|
||||
_width = widget.carton.width;
|
||||
_height = widget.carton.height;
|
||||
|
||||
// check carton size type
|
||||
List<CartonSize> cartonSizes = context.read<CartonSizeModel>().cartonSizes;
|
||||
|
||||
var sameLength =
|
||||
cartonSizes.any((size) => size.length == widget.carton.length);
|
||||
var sameWidth =
|
||||
cartonSizes.any((size) => size.width == widget.carton.width);
|
||||
var sameHeight =
|
||||
cartonSizes.any((size) => size.height == widget.carton.height);
|
||||
bool isStandartSize = sameLength && sameWidth && sameHeight;
|
||||
if (isStandartSize) {
|
||||
_cartonSizeType = standardCarton;
|
||||
_standardSize = cartonSizes.firstWhere((size) =>
|
||||
size.length == widget.carton.length &&
|
||||
size.width == widget.carton.width &&
|
||||
size.height == widget.carton.height);
|
||||
} else if (widget.carton.length == 0 &&
|
||||
widget.carton.width == 0 &&
|
||||
widget.carton.height == 0) {
|
||||
_cartonSizeType = packageCarton;
|
||||
} else {
|
||||
_cartonSizeType = customCarton;
|
||||
}
|
||||
|
||||
var s = await context
|
||||
.read<FcsShipmentModel>()
|
||||
@@ -70,7 +91,7 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
|
||||
|
||||
_cartons = await context
|
||||
.read<CartonModel>()
|
||||
.getCartonsByIds(widget.carton.mixCartonIDs);
|
||||
.getCartonsByIds(widget.carton.cartonIDs);
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
@@ -113,8 +134,16 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
|
||||
},
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
title: LocalText(context, 'box.update_title',
|
||||
color: primaryColor, fontSize: 20),
|
||||
title: Column(
|
||||
children: [
|
||||
LocalText(context, 'box.update_title',
|
||||
color: primaryColor, fontSize: 20),
|
||||
Text(
|
||||
widget.carton.cartonNumber ?? '',
|
||||
style: TextStyle(color: primaryColor, fontSize: 14),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
@@ -212,6 +241,35 @@ class _MixCartonEditorState extends State<MixCartonEditor> {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
double length = 0;
|
||||
double width = 0;
|
||||
double height = 0;
|
||||
|
||||
if (_cartonSizeType == standardCarton) {
|
||||
if (_standardSize != null) {
|
||||
length = _standardSize!.length;
|
||||
width = _standardSize!.width;
|
||||
height = _standardSize!.height;
|
||||
}
|
||||
} else if (_cartonSizeType == customCarton) {
|
||||
length = _length;
|
||||
width = _width;
|
||||
height = _height;
|
||||
} else {
|
||||
length = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
|
||||
var carton = Carton(
|
||||
id: widget.carton.id,
|
||||
cartonType: mix_carton,
|
||||
fcsShipmentID: _shipment?.id,
|
||||
length: length,
|
||||
width: width,
|
||||
height: height,
|
||||
cartons: _cartons);
|
||||
await context.read<CartonModel>().updateCarton(carton);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// ignore_for_file: deprecated_member_use
|
||||
|
||||
import 'package:fcs/pages/carton/model/carton_model.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@@ -187,7 +188,35 @@ class _MixCartonFormState extends State<MixCartonForm> {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
Navigator.pop(context, true);
|
||||
double length = 0;
|
||||
double width = 0;
|
||||
double height = 0;
|
||||
|
||||
if (_cartonSizeType == standardCarton) {
|
||||
if (_standardSize != null) {
|
||||
length = _standardSize!.length;
|
||||
width = _standardSize!.width;
|
||||
height = _standardSize!.height;
|
||||
}
|
||||
} else if (_cartonSizeType == customCarton) {
|
||||
length = _length;
|
||||
width = _width;
|
||||
height = _height;
|
||||
} else {
|
||||
length = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
||||
|
||||
var carton = Carton(
|
||||
cartonType: mix_carton,
|
||||
fcsShipmentID: _shipment?.id,
|
||||
length: length,
|
||||
width: width,
|
||||
height: height,
|
||||
cartons: _cartons);
|
||||
var c = await context.read<CartonModel>().createMixCarton(carton);
|
||||
Navigator.pop(context, c);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
|
||||
@@ -110,17 +110,14 @@ class _MixCartonSubmitState extends State<MixCartonSubmit> {
|
||||
final cartonType = Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: SubmitTextWidget(
|
||||
labelKey: 'box.carton.type',
|
||||
text: carton_mix_carton,
|
||||
// subText: boxDimension,
|
||||
),
|
||||
labelKey: 'box.carton.type', text: carton_mix_carton),
|
||||
);
|
||||
|
||||
final cartonSizeBox = Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: SubmitTextWidget(
|
||||
labelKey: 'box.carton_size',
|
||||
text: boxDimension ?? '',
|
||||
text: boxDimension ?? 'No defined size',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
@@ -68,8 +68,6 @@ class _TypeWidgetState extends State<TypeWidget> {
|
||||
}
|
||||
|
||||
_init() async {
|
||||
List<CartonSize> cartonSizes = context.read<CartonSizeModel>().cartonSizes;
|
||||
_selectStandardSize = widget.standardSize ?? cartonSizes.first;
|
||||
_cartionSizeType = widget.cartonSizeType;
|
||||
|
||||
_lengthController.text =
|
||||
@@ -79,6 +77,8 @@ class _TypeWidgetState extends State<TypeWidget> {
|
||||
_heightController.text =
|
||||
widget.height == null ? "0" : removeTrailingZeros(widget.height ?? 0);
|
||||
|
||||
_getStandardCartonSize();
|
||||
|
||||
_loadShipment();
|
||||
|
||||
if (mounted) {
|
||||
@@ -86,11 +86,24 @@ class _TypeWidgetState extends State<TypeWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
_getStandardCartonSize() {
|
||||
List<CartonSize> cartonSizes = context.read<CartonSizeModel>().cartonSizes;
|
||||
_selectStandardSize = widget.standardSize ?? cartonSizes.first;
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
_loadShipment() async {
|
||||
var fcsShipments =
|
||||
await context.read<FcsShipmentModel>().getActiveFcsShipments();
|
||||
_shipments = fcsShipments;
|
||||
_shipment = widget.shipment;
|
||||
if (_shipments.contains(widget.shipment)) {
|
||||
_shipment = widget.shipment;
|
||||
} else {
|
||||
_shipment = null;
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
@@ -99,6 +112,7 @@ class _TypeWidgetState extends State<TypeWidget> {
|
||||
@override
|
||||
void didUpdateWidget(covariant TypeWidget oldWidget) {
|
||||
_loadShipment();
|
||||
_getStandardCartonSize();
|
||||
super.didUpdateWidget(oldWidget);
|
||||
}
|
||||
|
||||
@@ -109,7 +123,7 @@ class _TypeWidgetState extends State<TypeWidget> {
|
||||
|
||||
bool isStandardSize = _cartionSizeType == standardCarton;
|
||||
bool isCustomSize = _cartionSizeType == customCarton;
|
||||
bool isNoneDefinedSize = _cartionSizeType == packageCartion;
|
||||
bool isNoneDefinedSize = _cartionSizeType == packageCarton;
|
||||
|
||||
final continueBtn = ContinueButton(onTap: () {
|
||||
double l = double.tryParse(_lengthController.text) ?? 0;
|
||||
@@ -287,16 +301,16 @@ class _TypeWidgetState extends State<TypeWidget> {
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_cartionSizeType = packageCartion;
|
||||
_cartionSizeType = packageCarton;
|
||||
});
|
||||
},
|
||||
child: Row(children: <Widget>[
|
||||
LocalRadio(
|
||||
value: packageCartion,
|
||||
value: packageCarton,
|
||||
groupValue: _cartionSizeType,
|
||||
onChanged: (p0) {
|
||||
setState(() {
|
||||
_cartionSizeType = packageCartion;
|
||||
_cartionSizeType = packageCarton;
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user