update package detal list and update cargo type input in carton section
This commit is contained in:
@@ -52,9 +52,9 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
List<TextEditingController> surchargeControllers = [];
|
||||
|
||||
bool get hasValueTotalWeight =>
|
||||
totalCtl.text.isNotEmpty && totalCtl.text != '0';
|
||||
totalCtl.text.isNotEmpty && totalCtl.text != '0.00';
|
||||
bool get hasValueCargoes =>
|
||||
_cargoTypes.isNotEmpty && _cargoTypes.every((e) => e.weight != 0);
|
||||
_cargoTypes.isNotEmpty && _cargoTypes.every((e) => e.weight != 0.00);
|
||||
|
||||
double get actualTotalWeight =>
|
||||
_cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
@@ -72,11 +72,12 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
_cargoTypes = List.from(widget.cargoTypes);
|
||||
for (var e in _cargoTypes) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = removeTrailingZeros(e.weight);
|
||||
editor.text = twoDecimalFormatted(
|
||||
double.tryParse(removeTrailingZeros(e.weight)) ?? 0);
|
||||
editor.addListener(inputChangeListener);
|
||||
cargoTypeControllers.add(editor);
|
||||
}
|
||||
onUpdated();
|
||||
_onPopulate();
|
||||
} else {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_openCargoTypeSelection();
|
||||
@@ -108,11 +109,14 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
|
||||
for (var e in _cargoTypes) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = '0';
|
||||
editor.text = '0.00';
|
||||
editor.addListener(inputChangeListener);
|
||||
cargoTypeControllers.add(editor);
|
||||
}
|
||||
|
||||
totalCtl.text = twoDecimalFormatted(
|
||||
double.tryParse(removeTrailingZeros(actualTotalWeight)) ?? 0);
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
@@ -133,9 +137,10 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
return emptyFields;
|
||||
}
|
||||
|
||||
void onUpdated() {
|
||||
void _onPopulate() {
|
||||
if (!hasValueTotalWeight && hasValueCargoes) {
|
||||
totalCtl.text = removeTrailingZeros(actualTotalWeight);
|
||||
totalCtl.text = twoDecimalFormatted(
|
||||
double.tryParse(removeTrailingZeros(actualTotalWeight)) ?? 0);
|
||||
error = null;
|
||||
} else {
|
||||
// auto populate remaining value
|
||||
@@ -155,8 +160,8 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
_cargoTypes.asMap().entries.forEach((e) {
|
||||
if (e.value.weight == 0) {
|
||||
e.value.weight = remainingWeight;
|
||||
cargoTypeControllers[e.key].text =
|
||||
removeTrailingZeros(e.value.weight);
|
||||
cargoTypeControllers[e.key].text = twoDecimalFormatted(
|
||||
double.tryParse(removeTrailingZeros(e.value.weight)) ?? 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -168,6 +173,18 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
void _onCheckTotalWeight(String value) {
|
||||
double totalWeight = double.tryParse(value) ?? 0;
|
||||
if (totalWeight != actualTotalWeight) {
|
||||
error = "Invalid total weight";
|
||||
} else {
|
||||
error = null;
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final senderBox = userDisplayBox(context,
|
||||
@@ -208,19 +225,30 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
CargoTypeAddition(cargoTypes: _cargoTypes)));
|
||||
if (cargoType == null) return;
|
||||
|
||||
if (!cargoType.isMixCargo) {
|
||||
_cargoTypes.add(cargoType);
|
||||
}
|
||||
_cargoTypes.sort((a, b) => (a == b ? 0 : (a.isMixCargo ? 1 : -1)));
|
||||
|
||||
// add cargo type
|
||||
if (cargoType.isMixCargo) {
|
||||
_cargoTypes.add(cargoType);
|
||||
int lastTrueIndex =
|
||||
_cargoTypes.lastIndexWhere((e) => e.isMixCargo);
|
||||
if (lastTrueIndex != -1) {
|
||||
_cargoTypes.insert(lastTrueIndex + 1, cargoType);
|
||||
} else {
|
||||
_cargoTypes.add(cargoType);
|
||||
}
|
||||
} else {
|
||||
int lastFalseIndex =
|
||||
_cargoTypes.lastIndexWhere((e) => !e.isMixCargo);
|
||||
if (lastFalseIndex != -1) {
|
||||
_cargoTypes.insert(lastFalseIndex + 1, cargoType);
|
||||
} else {
|
||||
_cargoTypes.insert(0, cargoType);
|
||||
}
|
||||
}
|
||||
|
||||
cargoTypeControllers.clear();
|
||||
for (var e in _cargoTypes) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = removeTrailingZeros(e.weight);
|
||||
editor.text = twoDecimalFormatted(
|
||||
double.tryParse(removeTrailingZeros(e.weight)) ?? 0);
|
||||
editor.addListener(inputChangeListener);
|
||||
cargoTypeControllers.add(editor);
|
||||
}
|
||||
@@ -230,177 +258,53 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
}),
|
||||
);
|
||||
|
||||
final cargosBox = Padding(
|
||||
final totalWeightBox = Padding(
|
||||
padding: const EdgeInsets.only(top: 5),
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
runSpacing: 25,
|
||||
children: _cargoTypes.asMap().entries.map((e) {
|
||||
var key = e.key;
|
||||
var c = e.value;
|
||||
return SizedBox(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 2.3,
|
||||
child: Column(
|
||||
child: Row(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
InkResponse(
|
||||
radius: 25,
|
||||
onTap: () {
|
||||
double totalWeight =
|
||||
double.tryParse(totalCtl.text) ?? 0;
|
||||
|
||||
if (actualTotalWeight > totalWeight) {
|
||||
error = "Exceed total weight";
|
||||
} else {
|
||||
double result = totalWeight - c.weight;
|
||||
totalCtl.text = removeTrailingZeros(result);
|
||||
}
|
||||
|
||||
_cargoTypes.removeAt(key);
|
||||
cargoTypeControllers.removeAt(key);
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
child: Icon(Feather.minus_circle, color: labelColor)),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: inputTextFieldWidget(context,
|
||||
lableText: c.name ?? "",
|
||||
controller: cargoTypeControllers[key],
|
||||
onFieldSubmitted: (value) {
|
||||
_cargoTypes[e.key].weight =
|
||||
double.tryParse(value) ?? 0;
|
||||
onUpdated();
|
||||
},
|
||||
suffixIcon: InkResponse(
|
||||
radius: 23,
|
||||
onTap: () {
|
||||
double totalWeight =
|
||||
(double.tryParse(totalCtl.text) ?? 0);
|
||||
|
||||
var list = _cargoTypes
|
||||
.where((e) => e.id != c.id)
|
||||
.toList();
|
||||
double resetValue = totalWeight -
|
||||
(list.fold(0,
|
||||
(sum, value) => sum + value.weight));
|
||||
setState(() {
|
||||
e.value.weight = resetValue;
|
||||
cargoTypeControllers[e.key].text =
|
||||
removeTrailingZeros(resetValue);
|
||||
});
|
||||
|
||||
onUpdated();
|
||||
},
|
||||
child: Icon(Ionicons.md_refresh_circle,
|
||||
color: labelColor, size: 22))),
|
||||
),
|
||||
c.isMixCargo
|
||||
? InkResponse(
|
||||
radius: 23,
|
||||
onTap: () async {
|
||||
List<CargoType>? cargoes = await showDialog(
|
||||
context: context,
|
||||
builder: (_) => MixCargoTypeAdditionDialog(
|
||||
cargoTypes: c.mixCargoes));
|
||||
if (cargoes == null) return;
|
||||
setState(() {
|
||||
c.mixCargoes = List.from(cargoes);
|
||||
});
|
||||
},
|
||||
child: Icon(Icons.add_circle,
|
||||
color: labelColor, size: 22))
|
||||
: const SizedBox()
|
||||
],
|
||||
),
|
||||
c.mixCargoes.isEmpty
|
||||
? const SizedBox()
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(top: 5),
|
||||
child: Column(
|
||||
children: c.mixCargoes.map((e) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 25),
|
||||
InkResponse(
|
||||
radius: 23,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
c.mixCargoes.remove(e);
|
||||
});
|
||||
},
|
||||
child: Icon(Feather.minus_circle,
|
||||
color: labelColor, size: 20)),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
child: Text(e.name ?? ""),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
);
|
||||
|
||||
final totalWeightBox = Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 2.3,
|
||||
child: Row(
|
||||
children: [
|
||||
InkResponse(
|
||||
radius: 25,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
totalCtl.clear();
|
||||
});
|
||||
},
|
||||
child: Icon(MaterialIcons.clear, color: labelColor)),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: inputTextFieldWidget(context,
|
||||
lableText: "Total",
|
||||
controller: totalCtl, onFieldSubmitted: (neValue) {
|
||||
if (hasValueCargoes) {
|
||||
double totalWeight = double.tryParse(neValue) ?? 0;
|
||||
if (totalWeight < actualTotalWeight) {
|
||||
InkResponse(
|
||||
radius: 25,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
error = "Invalid total weight";
|
||||
totalCtl.clear();
|
||||
});
|
||||
_onCheckTotalWeight(totalCtl.text);
|
||||
},
|
||||
child: Icon(MaterialIcons.clear, color: labelColor)),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: inputTextFieldWidget(context,
|
||||
lableText: "Total",
|
||||
controller: totalCtl, onFieldSubmitted: (newValue) {
|
||||
if (hasValueCargoes) {
|
||||
_onCheckTotalWeight(newValue);
|
||||
} else {
|
||||
setState(() {
|
||||
error = null;
|
||||
});
|
||||
_onPopulate();
|
||||
}
|
||||
} else {
|
||||
onUpdated();
|
||||
}
|
||||
},
|
||||
suffixIcon: InkResponse(
|
||||
radius: 23,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
totalCtl.text =
|
||||
removeTrailingZeros(actualTotalWeight);
|
||||
error = null;
|
||||
});
|
||||
},
|
||||
child: Icon(Ionicons.md_refresh_circle,
|
||||
color: labelColor, size: 22))),
|
||||
),
|
||||
],
|
||||
)),
|
||||
],
|
||||
},
|
||||
suffixIcon: InkResponse(
|
||||
radius: 23,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
totalCtl.text = twoDecimalFormatted(
|
||||
double.tryParse(removeTrailingZeros(
|
||||
actualTotalWeight)) ??
|
||||
0);
|
||||
error = null;
|
||||
});
|
||||
},
|
||||
child: Icon(Ionicons.md_refresh_circle,
|
||||
color: labelColor, size: 22))),
|
||||
),
|
||||
],
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final subchargeItemTitleBox = LocalTitle(
|
||||
@@ -481,17 +385,161 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
context, "Error", "Please insert surcharge item quantity");
|
||||
return;
|
||||
}
|
||||
|
||||
if (error != null) {
|
||||
showMsgDialog(
|
||||
context, "Error", "Please add the right cargo type weight");
|
||||
return;
|
||||
}
|
||||
widget.onContinue!(_cargoTypes, _surchareItems);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
final previousBtn = PreviousButton(onTap: () {
|
||||
if (error != null) {
|
||||
showMsgDialog(
|
||||
context, "Error", "Please add the right cargo type weight");
|
||||
return;
|
||||
}
|
||||
if (widget.onPrevious != null) {
|
||||
widget.onPrevious!(_cargoTypes, _surchareItems);
|
||||
}
|
||||
});
|
||||
|
||||
Widget cargoesWidget(List<CargoType> items) {
|
||||
List<Widget> widgets = [];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
var key = i;
|
||||
var c = items[i];
|
||||
|
||||
if (i > 0 && (!items[i - 1].isMixCargo && items[i].isMixCargo)) {
|
||||
widgets.add(Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 70),
|
||||
child: Divider(color: Colors.grey.shade300)));
|
||||
}
|
||||
|
||||
widgets.add(SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 2.3,
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
InkResponse(
|
||||
radius: 25,
|
||||
onTap: () {
|
||||
_cargoTypes.removeAt(key);
|
||||
cargoTypeControllers.removeAt(key);
|
||||
|
||||
_onCheckTotalWeight(totalCtl.text);
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
child: Icon(Feather.minus_circle, color: labelColor)),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: inputTextFieldWidget(context,
|
||||
lableText: c.name ?? "",
|
||||
controller: cargoTypeControllers[key],
|
||||
onFieldSubmitted: (value) {
|
||||
_cargoTypes[key].weight = double.tryParse(value) ?? 0;
|
||||
_onPopulate();
|
||||
},
|
||||
suffixIcon: InkResponse(
|
||||
radius: 23,
|
||||
onTap: () {
|
||||
double totalWeight =
|
||||
(double.tryParse(totalCtl.text) ?? 0);
|
||||
|
||||
var list = _cargoTypes
|
||||
.where((e) => e.id != c.id)
|
||||
.toList();
|
||||
double sum = (list.fold(
|
||||
0, (sum, value) => sum + value.weight));
|
||||
|
||||
if (sum > totalWeight) {
|
||||
error = "Exceed total weight";
|
||||
} else {
|
||||
error = null;
|
||||
double resetValue = totalWeight - sum;
|
||||
|
||||
setState(() {
|
||||
c.weight = resetValue;
|
||||
cargoTypeControllers[key].text =
|
||||
twoDecimalFormatted(double.tryParse(
|
||||
removeTrailingZeros(
|
||||
resetValue)) ??
|
||||
0);
|
||||
});
|
||||
_onPopulate();
|
||||
}
|
||||
},
|
||||
child: Icon(Ionicons.md_refresh_circle,
|
||||
color: labelColor, size: 22))),
|
||||
),
|
||||
c.isMixCargo
|
||||
? InkResponse(
|
||||
radius: 23,
|
||||
onTap: () async {
|
||||
List<CargoType>? cargoes = await showDialog(
|
||||
context: context,
|
||||
builder: (_) => MixCargoTypeAdditionDialog(
|
||||
cargoTypes: c.mixCargoes));
|
||||
if (cargoes == null) return;
|
||||
setState(() {
|
||||
c.mixCargoes = List.from(cargoes);
|
||||
});
|
||||
},
|
||||
child: Icon(Icons.add_circle,
|
||||
color: labelColor, size: 22))
|
||||
: const SizedBox()
|
||||
],
|
||||
),
|
||||
c.mixCargoes.isEmpty
|
||||
? const SizedBox()
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(top: 5),
|
||||
child: Column(
|
||||
children: c.mixCargoes.map((e) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 25),
|
||||
InkResponse(
|
||||
radius: 23,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
c.mixCargoes.remove(e);
|
||||
});
|
||||
},
|
||||
child: Icon(Feather.minus_circle,
|
||||
color: labelColor, size: 20)),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
child: Text(e.name ?? ""),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
)
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 5),
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
runSpacing: 25,
|
||||
children: widgets),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -502,9 +550,13 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
const SizedBox(height: 8),
|
||||
userRow,
|
||||
cargoTitle,
|
||||
cargosBox,
|
||||
cargoesWidget(_cargoTypes),
|
||||
const SizedBox(height: 15),
|
||||
Divider(),
|
||||
_cargoTypes.isNotEmpty
|
||||
? Divider(
|
||||
color: Colors.grey.shade300,
|
||||
)
|
||||
: const SizedBox(),
|
||||
const SizedBox(height: 5),
|
||||
error != null
|
||||
? Text(
|
||||
@@ -553,7 +605,11 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
onFieldSubmitted: onFieldSubmitted,
|
||||
readOnly: readOnly,
|
||||
decoration: InputDecoration(
|
||||
suffixIcon: suffixIcon,
|
||||
suffixIcon: Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: suffixIcon,
|
||||
),
|
||||
suffixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0),
|
||||
contentPadding: EdgeInsets.all(0),
|
||||
labelText: lableText,
|
||||
labelStyle: newLabelStyle(color: Colors.black54, fontSize: 17),
|
||||
|
||||
Reference in New Issue
Block a user