add fcs shipment in processing,update cargo types for carton
This commit is contained in:
@@ -39,11 +39,11 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
|
||||
p.isChecked = false;
|
||||
}
|
||||
|
||||
widget.cargoTypes.forEach((vp) {
|
||||
for (var vp in widget.cargoTypes) {
|
||||
if (p.id == vp.id) {
|
||||
p.qty = vp.qty;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
|
||||
131
lib/pages/carton/cargo_type_addition_dialog.dart
Normal file
131
lib/pages/carton/cargo_type_addition_dialog.dart
Normal file
@@ -0,0 +1,131 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../domain/entities/cargo_type.dart';
|
||||
import '../../helpers/theme.dart';
|
||||
import '../main/util.dart';
|
||||
import '../rates/model/shipment_rate_model.dart';
|
||||
import '../widgets/local_text.dart';
|
||||
|
||||
class CargoTypeAdditionDialog extends StatefulWidget {
|
||||
const CargoTypeAdditionDialog({super.key});
|
||||
|
||||
@override
|
||||
State<CargoTypeAdditionDialog> createState() =>
|
||||
_CargoTypeAdditionDialogState();
|
||||
}
|
||||
|
||||
class _CargoTypeAdditionDialogState extends State<CargoTypeAdditionDialog> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
List<CargoType> cargoTypes = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_init();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
_init() {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
cargoTypes =
|
||||
shipmentRateModel.rate.cargoTypes.map((e) => e.clone()).toList();
|
||||
var defaultCargoes = cargoTypes.where((e) => e.isDefault).toList();
|
||||
for (var p in cargoTypes) {
|
||||
if (defaultCargoes.any((e) => e.id == p.id)) {
|
||||
p.isChecked = true;
|
||||
} else {
|
||||
p.isChecked = false;
|
||||
}
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Center(
|
||||
child: LocalText(context, 'box.add.cargo_type',
|
||||
fontSize: 18, color: primaryColor, fontWeight: FontWeight.bold),
|
||||
),
|
||||
content: SizedBox(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: cargoTypes.map((p) {
|
||||
return ListTile(
|
||||
minTileHeight: 50,
|
||||
minVerticalPadding: 0,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
p.isChecked = !p.isChecked;
|
||||
});
|
||||
},
|
||||
title: Row(
|
||||
children: <Widget>[
|
||||
Checkbox(
|
||||
value: p.isChecked,
|
||||
activeColor: primaryColor,
|
||||
side: BorderSide(color: Colors.black38, width: 2),
|
||||
onChanged: (bool? value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
p.isChecked = value;
|
||||
});
|
||||
}
|
||||
}),
|
||||
Expanded(
|
||||
child: Text(
|
||||
p.name ?? "",
|
||||
style:
|
||||
TextStyle(fontSize: 15.0, color: Colors.black),
|
||||
),
|
||||
),
|
||||
],
|
||||
));
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: LocalText(context, 'btn.cancel',
|
||||
color: labelColor, fontSize: 14),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}),
|
||||
const SizedBox(width: 5),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: Size(80, 35),
|
||||
backgroundColor: primaryColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
),
|
||||
child: LocalText(context, 'btn.add',
|
||||
color: Colors.white, fontSize: 14),
|
||||
onPressed: () async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
_save();
|
||||
})
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
_save() {
|
||||
try {
|
||||
var selectedCargos = cargoTypes.where((e) => e.isChecked).toList();
|
||||
Navigator.pop<List<CargoType>>(context, selectedCargos);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,19 @@
|
||||
// ignore_for_file: unused_local_variable
|
||||
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../domain/entities/cargo_type.dart';
|
||||
import '../../domain/entities/user.dart';
|
||||
import '../main/util.dart';
|
||||
import '../rates/model/shipment_rate_model.dart';
|
||||
import '../widgets/continue_button.dart';
|
||||
import '../widgets/local_title.dart';
|
||||
import '../widgets/previous_button.dart';
|
||||
import 'cargo_type_addition.dart';
|
||||
import 'cargo_type_addition_dialog.dart';
|
||||
import 'mix_cargo_type_addition_dialog.dart';
|
||||
import 'surcharge_item_addition.dart';
|
||||
|
||||
typedef OnPrevious = Function(
|
||||
@@ -48,6 +50,12 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
List<TextEditingController> cargoTypeControllers = [];
|
||||
List<TextEditingController> surchargeControllers = [];
|
||||
|
||||
List<CargoType> _mixCargoTypes = [];
|
||||
List<TextEditingController> mixCargoTypeControllers = [];
|
||||
|
||||
bool get isKnownTotalWeight =>
|
||||
totalCtl.text.isNotEmpty && totalCtl.text != '0';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_init();
|
||||
@@ -55,38 +63,38 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
}
|
||||
|
||||
_init() {
|
||||
totalCtl.addListener(totalInputChangeListener);
|
||||
// for cargo types
|
||||
if (widget.cargoTypes.isNotEmpty) {
|
||||
_cargoTypes = List.from(widget.cargoTypes);
|
||||
List<CargoType> allCargoes = List.from(widget.cargoTypes);
|
||||
_cargoTypes = allCargoes.where((e) => !e.isMixCargo).toList();
|
||||
for (var e in _cargoTypes) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = removeTrailingZeros(e.weight);
|
||||
editor.addListener(inputChangeListener);
|
||||
cargoTypeControllers.add(editor);
|
||||
}
|
||||
_mixCargoTypes = allCargoes.where((e) => e.isMixCargo).toList();
|
||||
for (var e in _mixCargoTypes) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = removeTrailingZeros(e.weight);
|
||||
editor.addListener(inputChangeListener);
|
||||
mixCargoTypeControllers.add(editor);
|
||||
}
|
||||
_calculateTotalWeght();
|
||||
} else {
|
||||
var model = context.read<ShipmentRateModel>();
|
||||
var cargoes = model.rate.cargoTypes.map((e) => e.clone()).toList();
|
||||
|
||||
_cargoTypes = cargoes.where((e) => e.isDefault).toList();
|
||||
// ignore: unused_local_variable
|
||||
for (var e in _cargoTypes) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = '';
|
||||
editor.addListener(inputChangeListener);
|
||||
cargoTypeControllers.add(editor);
|
||||
}
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_openCargoTypeSelection();
|
||||
});
|
||||
}
|
||||
|
||||
//for surcharge items
|
||||
|
||||
if (widget.surchargeItems.isNotEmpty) {
|
||||
_surchareItems = List.from(widget.surchargeItems);
|
||||
for (var e in _surchareItems) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = e.qty.toString();
|
||||
editor.addListener(inputChangeListener);
|
||||
editor.addListener(inputChangeListenerForSurchage);
|
||||
surchargeControllers.add(editor);
|
||||
}
|
||||
}
|
||||
@@ -96,38 +104,85 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
_calculateTotalWeght() {
|
||||
double total = _cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
totalCtl.text = removeTrailingZeros(total);
|
||||
totalInputChangeListener() {
|
||||
print("Listen isKnownTotalWeight:$isKnownTotalWeight");
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
bool isFieldEmpty(int index) {
|
||||
return cargoTypeControllers[index].text.isEmpty;
|
||||
inputChangeListenerForSurchage() {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
List<int> getEmptyFields() {
|
||||
List<int> emptyFields = [];
|
||||
for (int i = 0; i < cargoTypeControllers.length; i++) {
|
||||
if (isFieldEmpty(i)) {
|
||||
emptyFields.add(i);
|
||||
}
|
||||
_openCargoTypeSelection() async {
|
||||
List<CargoType>? cargoes = await showDialog(
|
||||
context: context, builder: (_) => const CargoTypeAdditionDialog());
|
||||
if (cargoes == null) return;
|
||||
_cargoTypes = cargoes.where((e) => !e.isMixCargo).toList();
|
||||
_mixCargoTypes = cargoes.where((e) => e.isMixCargo).toList();
|
||||
|
||||
for (var e in _cargoTypes) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = '0';
|
||||
editor.addListener(inputChangeListener);
|
||||
cargoTypeControllers.add(editor);
|
||||
}
|
||||
|
||||
for (var e in _mixCargoTypes) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = '0';
|
||||
editor.addListener(inputChangeListener);
|
||||
mixCargoTypeControllers.add(editor);
|
||||
}
|
||||
_calculateTotalWeght();
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
return emptyFields;
|
||||
}
|
||||
|
||||
_calculateTotalWeght() {
|
||||
print("_calculateTotalWeght isKnownTotalWeight:$isKnownTotalWeight");
|
||||
double notMixTotal =
|
||||
_cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
double mixTotal =
|
||||
_mixCargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
double total = notMixTotal + mixTotal;
|
||||
if (isKnownTotalWeight) {
|
||||
} else {
|
||||
totalCtl.text = removeTrailingZeros(total);
|
||||
}
|
||||
}
|
||||
|
||||
// bool isFieldEmpty(int index) {
|
||||
// return cargoTypeControllers[index].text.isEmpty;
|
||||
// }
|
||||
|
||||
// List<int> getEmptyFields() {
|
||||
// List<int> emptyFields = [];
|
||||
// for (int i = 0; i < cargoTypeControllers.length; i++) {
|
||||
// if (isFieldEmpty(i)) {
|
||||
// emptyFields.add(i);
|
||||
// }
|
||||
// }
|
||||
// return emptyFields;
|
||||
// }
|
||||
|
||||
inputChangeListener() {
|
||||
List<int> emptyFields = getEmptyFields();
|
||||
|
||||
if (emptyFields.isEmpty) {
|
||||
_cargoTypes.asMap().entries.forEach((e) {
|
||||
_cargoTypes[e.key].weight =
|
||||
double.tryParse(cargoTypeControllers[e.key].text) ?? 0;
|
||||
});
|
||||
double total = _cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
setState(() {
|
||||
totalCtl.text = removeTrailingZeros(total);
|
||||
});
|
||||
}
|
||||
_cargoTypes.asMap().entries.forEach((e) {
|
||||
_cargoTypes[e.key].weight =
|
||||
double.tryParse(cargoTypeControllers[e.key].text) ?? 0;
|
||||
});
|
||||
_mixCargoTypes.asMap().entries.forEach((e) {
|
||||
_mixCargoTypes[e.key].weight =
|
||||
double.tryParse(mixCargoTypeControllers[e.key].text) ?? 0;
|
||||
});
|
||||
double notMixTotal =
|
||||
_cargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
double mixTotal =
|
||||
_mixCargoTypes.fold(0, (sum, value) => sum + value.weight);
|
||||
double total = notMixTotal + mixTotal;
|
||||
setState(() {
|
||||
totalCtl.text = removeTrailingZeros(total);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -163,23 +218,34 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
List<CargoType> allCargoTypes = _cargoTypes + _mixCargoTypes;
|
||||
CargoType? cargoType = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
CargoTypeAddition(cargoTypes: _cargoTypes)));
|
||||
CargoTypeAddition(cargoTypes: allCargoTypes)));
|
||||
if (cargoType == null) return;
|
||||
_cargoTypes.add(cargoType);
|
||||
if (cargoType.isMixCargo) {
|
||||
_mixCargoTypes.add(cargoType);
|
||||
mixCargoTypeControllers.clear();
|
||||
|
||||
cargoTypeControllers.clear();
|
||||
for (var e in _mixCargoTypes) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = removeTrailingZeros(e.weight);
|
||||
editor.addListener(inputChangeListener);
|
||||
mixCargoTypeControllers.add(editor);
|
||||
}
|
||||
} else {
|
||||
_cargoTypes.add(cargoType);
|
||||
cargoTypeControllers.clear();
|
||||
|
||||
for (var e in _cargoTypes) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = removeTrailingZeros(e.weight);
|
||||
editor.addListener(inputChangeListener);
|
||||
cargoTypeControllers.add(editor);
|
||||
for (var e in _cargoTypes) {
|
||||
var editor = TextEditingController();
|
||||
editor.text = removeTrailingZeros(e.weight);
|
||||
editor.addListener(inputChangeListener);
|
||||
cargoTypeControllers.add(editor);
|
||||
}
|
||||
}
|
||||
|
||||
_calculateTotalWeght();
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
@@ -187,44 +253,150 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
}),
|
||||
);
|
||||
|
||||
final cargosBox = Wrap(
|
||||
final cargosBox = Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
runSpacing: 15,
|
||||
children: _cargoTypes.asMap().entries.map((e) {
|
||||
var key = e.key;
|
||||
var c = e.value;
|
||||
return SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 2.3,
|
||||
child: Row(
|
||||
children: [
|
||||
InkResponse(
|
||||
radius: 23,
|
||||
onTap: () {
|
||||
_cargoTypes.removeAt(key);
|
||||
|
||||
double totalWeight =
|
||||
double.tryParse(totalCtl.text) ?? 0;
|
||||
double removeWeight =
|
||||
(double.tryParse(cargoTypeControllers[key].text) ??
|
||||
0);
|
||||
|
||||
if (totalWeight >= removeWeight) {
|
||||
double result = totalWeight - removeWeight;
|
||||
totalCtl.text = removeTrailingZeros(result);
|
||||
}
|
||||
|
||||
cargoTypeControllers[key].clear();
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
child: Icon(Feather.minus_circle, color: labelColor)),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: inputTextFieldWidget(context,
|
||||
lableText: c.name ?? "",
|
||||
controller: cargoTypeControllers[key],
|
||||
suffixIcon: InkResponse(
|
||||
radius: 23,
|
||||
onTap: () {},
|
||||
child: Icon(Ionicons.md_refresh_circle,
|
||||
color: labelColor))),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
);
|
||||
|
||||
final mixCargosBox = Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
runSpacing: 15,
|
||||
children: _cargoTypes.asMap().entries.map((e) {
|
||||
children: _mixCargoTypes.asMap().entries.map((e) {
|
||||
var key = e.key;
|
||||
var c = e.value;
|
||||
return SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 2.3,
|
||||
child: Row(
|
||||
child: Column(
|
||||
children: [
|
||||
InkResponse(
|
||||
radius: 25,
|
||||
onTap: () {
|
||||
_cargoTypes.removeAt(key);
|
||||
Row(
|
||||
children: [
|
||||
InkResponse(
|
||||
radius: 23,
|
||||
onTap: () {
|
||||
_mixCargoTypes.removeAt(key);
|
||||
|
||||
double totalWeight = double.tryParse(totalCtl.text) ?? 0;
|
||||
double removeWeight =
|
||||
(double.tryParse(cargoTypeControllers[key].text) ??
|
||||
double totalWeight =
|
||||
double.tryParse(totalCtl.text) ?? 0;
|
||||
double removeWeight = (double.tryParse(
|
||||
mixCargoTypeControllers[key].text) ??
|
||||
0);
|
||||
|
||||
if (totalWeight >= removeWeight) {
|
||||
double result = totalWeight - removeWeight;
|
||||
totalCtl.text = removeTrailingZeros(result);
|
||||
}
|
||||
if (totalWeight >= removeWeight) {
|
||||
double result = totalWeight - removeWeight;
|
||||
totalCtl.text = removeTrailingZeros(result);
|
||||
}
|
||||
|
||||
cargoTypeControllers[key].clear();
|
||||
mixCargoTypeControllers[key].clear();
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
child: Icon(Feather.minus_circle, color: labelColor)),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: inputTextFieldWidget(context,
|
||||
lableText: c.name ?? "",
|
||||
controller: cargoTypeControllers[key]),
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
},
|
||||
child: Icon(Feather.minus_circle,
|
||||
color: labelColor, size: 20)),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: inputTextFieldWidget(context,
|
||||
lableText: c.name ?? "",
|
||||
controller: mixCargoTypeControllers[key],
|
||||
suffixIcon: InkResponse(
|
||||
radius: 23,
|
||||
onTap: () {},
|
||||
child: Icon(Ionicons.md_refresh_circle,
|
||||
color: labelColor, size: 22))),
|
||||
),
|
||||
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))
|
||||
],
|
||||
),
|
||||
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()),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -250,28 +422,32 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
child: inputTextFieldWidget(context,
|
||||
lableText: "Total",
|
||||
controller: totalCtl,
|
||||
readOnly: getEmptyFields().isEmpty, onChanged: (neValue) {
|
||||
List<int> emptyFields = getEmptyFields();
|
||||
if (emptyFields.length == 1) {
|
||||
double totalWeight = double.tryParse(neValue) ?? 0;
|
||||
// onChanged: (neValue) {
|
||||
// List<int> emptyFields = getEmptyFields();
|
||||
// if (emptyFields.length == 1) {
|
||||
// double totalWeight = double.tryParse(neValue) ?? 0;
|
||||
|
||||
_cargoTypes.asMap().entries.forEach((e) {
|
||||
_cargoTypes[e.key].weight =
|
||||
double.tryParse(cargoTypeControllers[e.key].text) ??
|
||||
0;
|
||||
});
|
||||
double result = _cargoTypes.fold(
|
||||
0, (sum, value) => sum + value.weight);
|
||||
// _cargoTypes.asMap().entries.forEach((e) {
|
||||
// _cargoTypes[e.key].weight =
|
||||
// double.tryParse(cargoTypeControllers[e.key].text) ??
|
||||
// 0;
|
||||
// });
|
||||
// double result = _cargoTypes.fold(
|
||||
// 0, (sum, value) => sum + value.weight);
|
||||
|
||||
if (totalWeight >= result) {
|
||||
double remaining = totalWeight - result;
|
||||
setState(() {
|
||||
cargoTypeControllers[emptyFields.first].text =
|
||||
removeTrailingZeros(remaining);
|
||||
});
|
||||
}
|
||||
}
|
||||
}),
|
||||
// if (totalWeight >= result) {
|
||||
// double remaining = totalWeight - result;
|
||||
// setState(() {
|
||||
// cargoTypeControllers[emptyFields.first].text =
|
||||
// removeTrailingZeros(remaining);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
suffixIcon: InkResponse(
|
||||
radius: 23,
|
||||
child: Icon(Ionicons.md_refresh_circle,
|
||||
color: labelColor))),
|
||||
),
|
||||
],
|
||||
)),
|
||||
@@ -308,41 +484,44 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
}),
|
||||
);
|
||||
|
||||
final subChargeItemsBox = Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
runSpacing: 15,
|
||||
children: _surchareItems.asMap().entries.map((e) {
|
||||
var key = e.key;
|
||||
var c = e.value;
|
||||
return SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 2.3,
|
||||
child: Row(
|
||||
children: [
|
||||
InkResponse(
|
||||
radius: 25,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_surchareItems.removeAt(key);
|
||||
});
|
||||
},
|
||||
child: Icon(Feather.minus_circle, color: labelColor)),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: inputTextFieldWidget(
|
||||
context,
|
||||
lableText: c.name ?? "",
|
||||
controller: surchargeControllers[key],
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
_surchareItems[key].qty = int.tryParse(newValue) ?? 0;
|
||||
});
|
||||
},
|
||||
final subChargeItemsBox = Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
runSpacing: 15,
|
||||
children: _surchareItems.asMap().entries.map((e) {
|
||||
var key = e.key;
|
||||
var c = e.value;
|
||||
return SizedBox(
|
||||
width: MediaQuery.of(context).size.width / 2.3,
|
||||
child: Row(
|
||||
children: [
|
||||
InkResponse(
|
||||
radius: 25,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_surchareItems.removeAt(key);
|
||||
});
|
||||
},
|
||||
child: Icon(Feather.minus_circle, color: labelColor)),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: inputTextFieldWidget(
|
||||
context,
|
||||
lableText: c.name ?? "",
|
||||
controller: surchargeControllers[key],
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
_surchareItems[key].qty = int.tryParse(newValue) ?? 0;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList());
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
);
|
||||
|
||||
final continueBtn = ContinueButton(
|
||||
onTap: () {
|
||||
@@ -354,14 +533,17 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
return;
|
||||
}
|
||||
|
||||
widget.onContinue!(_cargoTypes, _surchareItems);
|
||||
var allCargoes = _cargoTypes + _mixCargoTypes;
|
||||
|
||||
widget.onContinue!(allCargoes, _surchareItems);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
final previousBtn = PreviousButton(onTap: () {
|
||||
if (widget.onPrevious != null) {
|
||||
widget.onPrevious!(_cargoTypes, _surchareItems);
|
||||
var allCargoes = _cargoTypes + _mixCargoTypes;
|
||||
widget.onPrevious!(allCargoes, _surchareItems);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -376,9 +558,18 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
userRow,
|
||||
cargoTitle,
|
||||
cargosBox,
|
||||
const SizedBox(height: 15),
|
||||
Divider(),
|
||||
const SizedBox(height: 5),
|
||||
_mixCargoTypes.isNotEmpty && _cargoTypes.isNotEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 100, vertical: 25),
|
||||
child: Divider(color: Colors.grey.shade300),
|
||||
)
|
||||
: const SizedBox(),
|
||||
mixCargosBox,
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 25),
|
||||
child: Divider(color: Colors.grey.shade300),
|
||||
),
|
||||
totalWeightBox,
|
||||
subchargeItemTitleBox,
|
||||
subChargeItemsBox,
|
||||
@@ -408,7 +599,8 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
{required String lableText,
|
||||
TextEditingController? controller,
|
||||
Function(String)? onChanged,
|
||||
bool readOnly = false}) {
|
||||
bool readOnly = false,
|
||||
Widget? suffixIcon}) {
|
||||
return TextFormField(
|
||||
controller: controller,
|
||||
style: textStyle,
|
||||
@@ -417,6 +609,7 @@ class _CargoWidgetState extends State<CargoWidget> {
|
||||
onChanged: onChanged,
|
||||
readOnly: readOnly,
|
||||
decoration: InputDecoration(
|
||||
suffixIcon: suffixIcon,
|
||||
contentPadding: EdgeInsets.all(0),
|
||||
labelText: lableText,
|
||||
labelStyle: newLabelStyle(color: Colors.black54, fontSize: 17),
|
||||
|
||||
@@ -295,18 +295,42 @@ class _CartonInfoState extends State<CartonInfo> {
|
||||
padding: const EdgeInsets.symmetric(vertical: 2),
|
||||
child: Container(
|
||||
color: e.key.isEven ? Colors.grey.shade300 : oddColor,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
e.value.name ?? "",
|
||||
style:
|
||||
TextStyle(color: Colors.black, fontSize: 15),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
e.value.name ?? "",
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 15),
|
||||
),
|
||||
Text(
|
||||
"${removeTrailingZeros(e.value.weight)} lb",
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 15))
|
||||
],
|
||||
),
|
||||
Text("${removeTrailingZeros(e.value.weight)} lb",
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 15))
|
||||
e.value.isMixCargo
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(left: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: e.value.mixCargoes.map((c) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 2),
|
||||
child: Text(
|
||||
"- ${c.name}",
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
)
|
||||
: const SizedBox()
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -236,6 +236,7 @@ class _CartonPackageFormState extends State<CartonPackageForm> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
_create() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
|
||||
134
lib/pages/carton/mix_cargo_type_addition_dialog.dart
Normal file
134
lib/pages/carton/mix_cargo_type_addition_dialog.dart
Normal file
@@ -0,0 +1,134 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../domain/entities/cargo_type.dart';
|
||||
import '../../helpers/theme.dart';
|
||||
import '../main/util.dart';
|
||||
import '../rates/model/shipment_rate_model.dart';
|
||||
import '../widgets/local_text.dart';
|
||||
|
||||
class MixCargoTypeAdditionDialog extends StatefulWidget {
|
||||
final List<CargoType> cargoTypes;
|
||||
const MixCargoTypeAdditionDialog({super.key, required this.cargoTypes});
|
||||
|
||||
@override
|
||||
State<MixCargoTypeAdditionDialog> createState() =>
|
||||
_MixCargoTypeAdditionDialogState();
|
||||
}
|
||||
|
||||
class _MixCargoTypeAdditionDialogState
|
||||
extends State<MixCargoTypeAdditionDialog> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
List<CargoType> cargoTypes = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_init();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
_init() {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
var cargoes =
|
||||
shipmentRateModel.rate.cargoTypes.map((e) => e.clone()).toList();
|
||||
cargoTypes = cargoes.where((e) => !e.isMixCargo).toList();
|
||||
|
||||
for (var p in cargoTypes) {
|
||||
if (widget.cargoTypes.any((e) => e.id == p.id)) {
|
||||
p.isChecked = true;
|
||||
} else {
|
||||
p.isChecked = false;
|
||||
}
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Center(
|
||||
child: LocalText(context, 'box.mix_cargo.title',
|
||||
fontSize: 18, color: primaryColor, fontWeight: FontWeight.bold),
|
||||
),
|
||||
content: SizedBox(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: cargoTypes.map((p) {
|
||||
return ListTile(
|
||||
minTileHeight: 50,
|
||||
minVerticalPadding: 0,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
p.isChecked = !p.isChecked;
|
||||
});
|
||||
},
|
||||
title: Row(
|
||||
children: <Widget>[
|
||||
Checkbox(
|
||||
value: p.isChecked,
|
||||
activeColor: primaryColor,
|
||||
side: BorderSide(color: Colors.black38, width: 2),
|
||||
onChanged: (bool? value) {
|
||||
if (value != null) {
|
||||
setState(() {
|
||||
p.isChecked = value;
|
||||
});
|
||||
}
|
||||
}),
|
||||
Expanded(
|
||||
child: Text(
|
||||
p.name ?? "",
|
||||
style:
|
||||
TextStyle(fontSize: 15.0, color: Colors.black),
|
||||
),
|
||||
),
|
||||
],
|
||||
));
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: LocalText(context, 'btn.cancel',
|
||||
color: labelColor, fontSize: 14),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
}),
|
||||
const SizedBox(width: 5),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: Size(80, 35),
|
||||
backgroundColor: primaryColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
),
|
||||
child: LocalText(context, 'btn.add',
|
||||
color: Colors.white, fontSize: 14),
|
||||
onPressed: () async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
_save();
|
||||
})
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
_save() {
|
||||
try {
|
||||
var selectedCargos = cargoTypes.where((e) => e.isChecked).toList();
|
||||
Navigator.pop<List<CargoType>>(context, selectedCargos);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class PackageSelectionModel extends BaseModel {
|
||||
whereIn: [package_processed_status, package_packed_status])
|
||||
.where("sender_id", isEqualTo: senderId)
|
||||
.where("user_id", isEqualTo: consigneeId)
|
||||
// .where("fcs_shipment_id", isEqualTo: shipmentId)
|
||||
.where("fcs_shipment_id", isEqualTo: shipmentId)
|
||||
.where("is_deleted", isEqualTo: false)
|
||||
.orderBy("created_date", descending: true)
|
||||
.get(const GetOptions(source: Source.server));
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../../domain/entities/package.dart';
|
||||
import '../../domain/entities/user.dart';
|
||||
import '../main/util.dart';
|
||||
import '../widgets/continue_button.dart';
|
||||
import '../widgets/local_text.dart';
|
||||
import '../widgets/local_title.dart';
|
||||
import '../widgets/previous_button.dart';
|
||||
import 'model/package_selection_model.dart';
|
||||
@@ -41,6 +42,7 @@ class _PackagesWidgetState extends State<PackagesWidget> {
|
||||
final _scrollController = ScrollController();
|
||||
bool _down = true;
|
||||
List<Package> _packages = [];
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -56,12 +58,14 @@ class _PackagesWidgetState extends State<PackagesWidget> {
|
||||
|
||||
_init() async {
|
||||
_packages.clear();
|
||||
_isLoading = true;
|
||||
var packageModel = context.read<PackageSelectionModel>();
|
||||
var list = await packageModel.getActivePackages(
|
||||
shipmentId: widget.shipment.id!,
|
||||
senderId: widget.sender.id!,
|
||||
consigneeId: widget.consignee.id!);
|
||||
_packages = List.from(list);
|
||||
_isLoading = false;
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
@@ -93,6 +97,10 @@ class _PackagesWidgetState extends State<PackagesWidget> {
|
||||
|
||||
final continueBtn = ContinueButton(
|
||||
onTap: () {
|
||||
if (_packages.isEmpty) {
|
||||
showMsgDialog(context, 'Error', "Please add the packages");
|
||||
return false;
|
||||
}
|
||||
if (widget.onContinue != null) {
|
||||
widget.onContinue!(_packages);
|
||||
}
|
||||
@@ -135,21 +143,25 @@ class _PackagesWidgetState extends State<PackagesWidget> {
|
||||
: const SizedBox(),
|
||||
),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
color: primaryColor,
|
||||
onRefresh: () async {
|
||||
_init();
|
||||
},
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
controller: _scrollController,
|
||||
shrinkWrap: true,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
itemBuilder: (context, index) {
|
||||
Package package = _packages[index];
|
||||
return packageRow(context, package);
|
||||
child: _packages.isEmpty && !_isLoading
|
||||
? Center(
|
||||
child: LocalText(context, 'box.no_package',
|
||||
color: Colors.black, fontSize: 15))
|
||||
: RefreshIndicator(
|
||||
color: primaryColor,
|
||||
onRefresh: () async {
|
||||
_init();
|
||||
},
|
||||
itemCount: _packages.length)),
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
controller: _scrollController,
|
||||
shrinkWrap: true,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
itemBuilder: (context, index) {
|
||||
Package package = _packages[index];
|
||||
return packageRow(context, package);
|
||||
},
|
||||
itemCount: _packages.length)),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user