update cargo type form from rate, update carton info and form
This commit is contained in:
@@ -12,7 +12,8 @@ import '../widgets/continue_button.dart';
|
||||
import '../widgets/display_text.dart';
|
||||
import '../widgets/local_title.dart';
|
||||
import '../widgets/previous_button.dart';
|
||||
import 'custom_duty_addition.dart';
|
||||
import 'cargo_type_addition.dart';
|
||||
import 'surcharge_item_addition.dart';
|
||||
|
||||
typedef OnPrevious = Function(
|
||||
List<CargoType> cargoTypes, List<CargoType> customDuties);
|
||||
@@ -56,28 +57,20 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
|
||||
_init() {
|
||||
// for cargo types
|
||||
var model = context.read<ShipmentRateModel>();
|
||||
_cargoTypes = model.rate.cargoTypes.map((e) => e.clone()).toList();
|
||||
|
||||
if (widget.cargoTypes.isNotEmpty) {
|
||||
_cargoTypes.forEach((mp) {
|
||||
mp.weight = 0;
|
||||
widget.cargoTypes.forEach((vp) {
|
||||
if (mp.id == vp.id) {
|
||||
mp.weight = vp.weight;
|
||||
}
|
||||
});
|
||||
});
|
||||
_cargoTypes = List.from(widget.cargoTypes);
|
||||
_cargoTypes.forEach((e) {
|
||||
var editor = new TextEditingController();
|
||||
editor.text = removeTrailingZeros(e.weight);
|
||||
editor.addListener(inputChangeListener);
|
||||
_cargoTypeControllers.add(editor);
|
||||
});
|
||||
|
||||
double total = _cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
_totalCtl.text = removeTrailingZeros(total);
|
||||
_calculateTotalWeght();
|
||||
} else {
|
||||
var model = context.read<ShipmentRateModel>();
|
||||
var cargoes = model.rate.cargoTypes.map((e) => e.clone()).toList();
|
||||
|
||||
_cargoTypes = cargoes.where((e) => e.isDefault).toList();
|
||||
_cargoTypes.forEach((e) {
|
||||
var editor = new TextEditingController();
|
||||
editor.text = '';
|
||||
@@ -103,6 +96,11 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
_calculateTotalWeght() {
|
||||
double total = _cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
_totalCtl.text = removeTrailingZeros(total);
|
||||
}
|
||||
|
||||
bool isFieldEmpty(int index) {
|
||||
return _cargoTypeControllers[index].text.isEmpty;
|
||||
}
|
||||
@@ -158,6 +156,39 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
],
|
||||
);
|
||||
|
||||
final cargoTitle = LocalTitle(
|
||||
textKey: "box.input_cargo_weight",
|
||||
topPadding: 0,
|
||||
trailing: IconButton(
|
||||
icon: Icon(
|
||||
Icons.add_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
CargoType? cargoType = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
CargoTypeAddition(cargoTypes: _cargoTypes)));
|
||||
if (cargoType == null) return;
|
||||
_cargoTypes.add(cargoType);
|
||||
|
||||
_cargoTypeControllers.clear();
|
||||
|
||||
_cargoTypes.forEach((e) {
|
||||
var editor = new TextEditingController();
|
||||
editor.text = removeTrailingZeros(e.weight);
|
||||
editor.addListener(inputChangeListener);
|
||||
_cargoTypeControllers.add(editor);
|
||||
});
|
||||
|
||||
_calculateTotalWeght();
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
final cargosBox = Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
runSpacing: 15,
|
||||
@@ -171,6 +202,8 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
InkResponse(
|
||||
radius: 25,
|
||||
onTap: () {
|
||||
_cargoTypes.removeAt(key);
|
||||
|
||||
double totalWeight = double.tryParse(_totalCtl.text) ?? 0;
|
||||
double removeWeight =
|
||||
(double.tryParse(_cargoTypeControllers[key].text) ??
|
||||
@@ -182,11 +215,12 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
}
|
||||
|
||||
_cargoTypeControllers[key].clear();
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
child: Icon(MaterialIcons.clear, color: labelColor)),
|
||||
child: Icon(Feather.minus_circle, color: labelColor)),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: inputTextFieldWidget(context,
|
||||
@@ -254,14 +288,14 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
List<CargoType>? customList = await Navigator.push<List<CargoType>>(
|
||||
CargoType? surchargeItem = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
CustomDutyAddition(customDuties: _surchareItems)));
|
||||
if (customList == null) return;
|
||||
SurchargeItemAddition(items: _surchareItems)));
|
||||
if (surchargeItem == null) return;
|
||||
|
||||
_surchareItems = List.from(customList);
|
||||
_surchareItems.add(surchargeItem);
|
||||
|
||||
_surchargeControllers.clear();
|
||||
_surchareItems.asMap().entries.forEach((e) {
|
||||
@@ -315,10 +349,11 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
final continueBtn = ContinueButton(
|
||||
onTap: () {
|
||||
if (widget.onContinue != null) {
|
||||
|
||||
if(_surchareItems.isNotEmpty && _surchareItems.any((item)=> item.qty == 0)){
|
||||
showMsgDialog(context, "Error", "Please insert surcharge item quantity");
|
||||
return;
|
||||
if (_surchareItems.isNotEmpty &&
|
||||
_surchareItems.any((item) => item.qty == 0)) {
|
||||
showMsgDialog(
|
||||
context, "Error", "Please insert surcharge item quantity");
|
||||
return;
|
||||
}
|
||||
|
||||
widget.onContinue!(_cargoTypes, _surchareItems);
|
||||
@@ -341,7 +376,7 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
userRow,
|
||||
LocalTitle(textKey: "box.input_cargo_weight", topPadding: 5),
|
||||
cargoTitle,
|
||||
cargosBox,
|
||||
const SizedBox(height: 15),
|
||||
Divider(),
|
||||
|
||||
Reference in New Issue
Block a user