Merge branch 'master' of https://git.mokkon.com/sainw/fcs
This commit is contained in:
@@ -299,6 +299,7 @@
|
|||||||
"box.mix_caton_title":"Mix cartons",
|
"box.mix_caton_title":"Mix cartons",
|
||||||
"box.min_caton.form.title":"Mix Carton",
|
"box.min_caton.form.title":"Mix Carton",
|
||||||
"box.mix_carton_btn":"Create mix carton",
|
"box.mix_carton_btn":"Create mix carton",
|
||||||
|
"box.mix_type":"Mix Box Types",
|
||||||
"Boxes End ================================================================":"",
|
"Boxes End ================================================================":"",
|
||||||
|
|
||||||
"Delivery Start ================================================================":"",
|
"Delivery Start ================================================================":"",
|
||||||
|
|||||||
@@ -299,6 +299,7 @@
|
|||||||
"box.mix_caton_title":"Mix cartons",
|
"box.mix_caton_title":"Mix cartons",
|
||||||
"box.min_caton.form.title":"Mix Carton",
|
"box.min_caton.form.title":"Mix Carton",
|
||||||
"box.mix_carton_btn":"Create mix carton",
|
"box.mix_carton_btn":"Create mix carton",
|
||||||
|
"box.mix_type":"Mix Box Types",
|
||||||
"Boxes End ================================================================":"",
|
"Boxes End ================================================================":"",
|
||||||
|
|
||||||
"Delivery Start ================================================================":"",
|
"Delivery Start ================================================================":"",
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ class Carton {
|
|||||||
String fcsShipmentNumber;
|
String fcsShipmentNumber;
|
||||||
String mixCartonID;
|
String mixCartonID;
|
||||||
String mixCartonNumber;
|
String mixCartonNumber;
|
||||||
|
String cartonSizeID;
|
||||||
|
String cartonSizeName;
|
||||||
|
String mixBoxType;
|
||||||
|
|
||||||
int rate;
|
int rate;
|
||||||
int weight;
|
int weight;
|
||||||
@@ -158,7 +161,10 @@ class Carton {
|
|||||||
this.mixCartonID,
|
this.mixCartonID,
|
||||||
this.mixCartonNumber,
|
this.mixCartonNumber,
|
||||||
this.isShipmentCarton = false,
|
this.isShipmentCarton = false,
|
||||||
this.deliveryAddress});
|
this.deliveryAddress,
|
||||||
|
this.cartonSizeID,
|
||||||
|
this.cartonSizeName,
|
||||||
|
this.mixBoxType});
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
|
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class _CargoTableState extends State<CargoTable> {
|
|||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
child: MyDataTable(
|
child: MyDataTable(
|
||||||
headingRowHeight: 40,
|
headingRowHeight: 40,
|
||||||
columnSpacing: 140,
|
columnSpacing: 50,
|
||||||
columns: [
|
columns: [
|
||||||
MyDataColumn(
|
MyDataColumn(
|
||||||
label: LocalText(
|
label: LocalText(
|
||||||
@@ -33,6 +33,13 @@ class _CargoTableState extends State<CargoTable> {
|
|||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
MyDataColumn(
|
||||||
|
label: LocalText(
|
||||||
|
context,
|
||||||
|
"cargo.qty",
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
),
|
||||||
MyDataColumn(
|
MyDataColumn(
|
||||||
label: LocalText(
|
label: LocalText(
|
||||||
context,
|
context,
|
||||||
@@ -60,6 +67,19 @@ class _CargoTableState extends State<CargoTable> {
|
|||||||
c.name == null ? "" : c.name,
|
c.name == null ? "" : c.name,
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
)),
|
)),
|
||||||
|
MyDataCell(c.qty == null || c.qty == 0
|
||||||
|
? Center(
|
||||||
|
child: Text(
|
||||||
|
"-",
|
||||||
|
style: textStyle,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Center(
|
||||||
|
child: Text(
|
||||||
|
c.qty.toString(),
|
||||||
|
style: textStyle,
|
||||||
|
),
|
||||||
|
)),
|
||||||
MyDataCell(
|
MyDataCell(
|
||||||
Text(c.weight == null ? "0" : c.weight.toStringAsFixed(2),
|
Text(c.weight == null ? "0" : c.weight.toStringAsFixed(2),
|
||||||
style: textStyle),
|
style: textStyle),
|
||||||
@@ -80,6 +100,7 @@ class _CargoTableState extends State<CargoTable> {
|
|||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
|
MyDataCell(Text("")),
|
||||||
MyDataCell(
|
MyDataCell(
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(right: 48.0),
|
padding: const EdgeInsets.only(right: 48.0),
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import 'package:fcs/pages/widgets/progress.dart';
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'input_text_border.dart';
|
|
||||||
|
|
||||||
class CargoTypeAddition extends StatefulWidget {
|
class CargoTypeAddition extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@@ -43,38 +42,6 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final cargoTableTitleBox = Container(
|
|
||||||
padding: EdgeInsets.only(left: 0.0, right: 10.0, top: 20),
|
|
||||||
child: Row(
|
|
||||||
children: <Widget>[
|
|
||||||
SizedBox(
|
|
||||||
width: 50,
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: LocalText(
|
|
||||||
context,
|
|
||||||
"cargo.type",
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: 40,
|
|
||||||
),
|
|
||||||
LocalText(
|
|
||||||
context,
|
|
||||||
"cargo.qty",
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
Spacer(),
|
|
||||||
LocalText(
|
|
||||||
context,
|
|
||||||
"cargo.weight",
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
List<Widget> getCargoRowList() {
|
List<Widget> getCargoRowList() {
|
||||||
return cargos.map((c) {
|
return cargos.map((c) {
|
||||||
return Container(
|
return Container(
|
||||||
@@ -115,89 +82,6 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
|
|||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> _getCargoRowList() {
|
|
||||||
return cargos.map((c) {
|
|
||||||
return Container(
|
|
||||||
child: Container(
|
|
||||||
padding:
|
|
||||||
EdgeInsets.only(left: 0.0, right: 5.0, top: 3.0, bottom: 3.0),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
border: Border(
|
|
||||||
bottom: BorderSide(color: Colors.grey[350], width: 1),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: <Widget>[
|
|
||||||
Checkbox(
|
|
||||||
value: c.isChecked,
|
|
||||||
activeColor: primaryColor,
|
|
||||||
onChanged: (bool check) {
|
|
||||||
setState(() {
|
|
||||||
c.isChecked = check;
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
Expanded(child: new Text(c.name, style: textStyle)),
|
|
||||||
SizedBox(
|
|
||||||
width: c.isCutomDuty ? 50 : 40,
|
|
||||||
child: c.isCutomDuty
|
|
||||||
? InkWell(
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
cargos.removeWhere((t) => t.name == c.name);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: Icon(
|
|
||||||
Icons.remove_circle,
|
|
||||||
color: Colors.black45,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: Container(),
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
height: 30,
|
|
||||||
width: 50,
|
|
||||||
child: c.isCutomDuty
|
|
||||||
? InputTextBorder(
|
|
||||||
onAdd: (value) {
|
|
||||||
setState(() {
|
|
||||||
if (value == "" || value == null) {
|
|
||||||
c.isChecked = false;
|
|
||||||
} else {
|
|
||||||
c.qty = int.parse(value);
|
|
||||||
c.isChecked = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: Center(child: Text("-")),
|
|
||||||
),
|
|
||||||
Spacer(),
|
|
||||||
Container(
|
|
||||||
height: 30,
|
|
||||||
width: 60,
|
|
||||||
child: Center(
|
|
||||||
child: Text(
|
|
||||||
c.weight == null ? "" : c.weight.toStringAsFixed(2))),
|
|
||||||
// child: InputTextBorder(
|
|
||||||
// onAdd: (value) {
|
|
||||||
// setState(() {
|
|
||||||
// if (value == "" || value == null) {
|
|
||||||
// c.isChecked = false;
|
|
||||||
// } else {
|
|
||||||
// c.weight = double.parse(value);
|
|
||||||
// c.isChecked = true;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// },
|
|
||||||
// ),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
final saveBtn = fcsButton(
|
final saveBtn = fcsButton(
|
||||||
context,
|
context,
|
||||||
getLocalString(context, 'box.cargo.save.btn'),
|
getLocalString(context, 'box.cargo.save.btn'),
|
||||||
@@ -246,10 +130,6 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
|
|||||||
_addCustom(customDuty);
|
_addCustom(customDuty);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
// cargoTableTitleBox,
|
|
||||||
// Divider(
|
|
||||||
// color: Colors.grey[400],
|
|
||||||
// ),
|
|
||||||
Column(
|
Column(
|
||||||
children: getCargoRowList(),
|
children: getCargoRowList(),
|
||||||
),
|
),
|
||||||
@@ -269,8 +149,8 @@ class _CargoTypeAdditionState extends State<CargoTypeAddition> {
|
|||||||
if (cargos.any((c) => c.name == customDuty.productType)) return;
|
if (cargos.any((c) => c.name == customDuty.productType)) return;
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
cargos.add(
|
cargos.add(CargoType(
|
||||||
CargoType(name: customDuty.productType, isCutomDuty: true, qty: 1));
|
name: customDuty.productType, isCutomDuty: true, qty: 1, weight: 0));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ typedef OnRemove(CargoType cargoType);
|
|||||||
|
|
||||||
class CargoTable extends StatefulWidget {
|
class CargoTable extends StatefulWidget {
|
||||||
final List<CargoType> cargoTypes;
|
final List<CargoType> cargoTypes;
|
||||||
|
final bool isNew;
|
||||||
final OnAdd onAdd;
|
final OnAdd onAdd;
|
||||||
final OnRemove onRemove;
|
final OnRemove onRemove;
|
||||||
|
|
||||||
const CargoTable({Key key, this.cargoTypes, this.onAdd, this.onRemove})
|
const CargoTable(
|
||||||
|
{Key key, this.cargoTypes, this.isNew, this.onAdd, this.onRemove})
|
||||||
: super(key: key);
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -31,6 +33,15 @@ class _CargoTableState extends State<CargoTable> {
|
|||||||
List<String> _list = [];
|
List<String> _list = [];
|
||||||
List<String> _types = [];
|
List<String> _types = [];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
if (!widget.isNew) {
|
||||||
|
totalWeight = widget.cargoTypes
|
||||||
|
.fold(0, (previous, current) => previous + current.weight);
|
||||||
|
}
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
remainingWeight =
|
remainingWeight =
|
||||||
@@ -79,61 +90,17 @@ class _CargoTableState extends State<CargoTable> {
|
|||||||
|
|
||||||
var rows = widget.cargoTypes.map((c) {
|
var rows = widget.cargoTypes.map((c) {
|
||||||
return MyDataRow(
|
return MyDataRow(
|
||||||
onSelectChanged: (bool selected) async {
|
onSelectChanged: (bool selected) async {},
|
||||||
// if (this.totalWeight <= 0) {
|
|
||||||
// showMsgDialog(context, "Error", "Please insert total weight");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (c.isCutomDuty) return;
|
|
||||||
// CargoType cargo = await Navigator.push<CargoType>(
|
|
||||||
// context,
|
|
||||||
// CupertinoPageRoute(
|
|
||||||
// builder: (context) => CargoTypeEditor(
|
|
||||||
// cargo: c,
|
|
||||||
// )));
|
|
||||||
// if (widget.onAdd != null) widget.onAdd(cargo);
|
|
||||||
// if (cargo == null) return;
|
|
||||||
|
|
||||||
// this._cargos.add(cargo);
|
|
||||||
// if (this.remainingWeight <= 0) return;
|
|
||||||
// this.remainingWeight -= cargo.weight;
|
|
||||||
|
|
||||||
// this._cargos.forEach((c) {
|
|
||||||
// _list.add(c.name);
|
|
||||||
// });
|
|
||||||
// widget.cargoTypes.forEach((c) {
|
|
||||||
// _types.add(c.name);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// if (this._cargos.length == widget.cargoTypes.length - 1) {
|
|
||||||
// _types.forEach((t) {
|
|
||||||
// if (!_list.contains(t)) {
|
|
||||||
// widget.cargoTypes.forEach((c) {
|
|
||||||
// if (c.name == t) {
|
|
||||||
// c.weight = this.remainingWeight;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
cells: [
|
cells: [
|
||||||
MyDataCell(Row(
|
MyDataCell(
|
||||||
children: [
|
|
||||||
new Text(
|
new Text(
|
||||||
c.name == null ? "" : c.name,
|
c.name == null ? "" : c.name,
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
),
|
),
|
||||||
new Text(
|
|
||||||
c.qty == null ? "" : " x ${c.qty.toString()}",
|
|
||||||
style: TextStyle(color: Colors.grey),
|
|
||||||
),
|
),
|
||||||
],
|
|
||||||
)),
|
|
||||||
MyDataCell(
|
MyDataCell(
|
||||||
c.isCutomDuty
|
c.isCutomDuty
|
||||||
? InkWell(
|
? GestureDetector(
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
String _t = await showDialog(
|
String _t = await showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
|||||||
@@ -90,9 +90,9 @@ class _CartonEditorState extends State<CartonEditor> {
|
|||||||
cargoTypes: [],
|
cargoTypes: [],
|
||||||
packages: [],
|
packages: [],
|
||||||
);
|
);
|
||||||
_lengthController.text = "";
|
_lengthController.text = "0";
|
||||||
_widthController.text = "";
|
_widthController.text = "0";
|
||||||
_heightController.text = "";
|
_heightController.text = "0";
|
||||||
_isNew = true;
|
_isNew = true;
|
||||||
_selectedCartonType = carton_from_packages;
|
_selectedCartonType = carton_from_packages;
|
||||||
_selectedMixType = mix_delivery;
|
_selectedMixType = mix_delivery;
|
||||||
@@ -256,28 +256,6 @@ class _CartonEditorState extends State<CartonEditor> {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
final _cartonTitleBox = Container(
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
|
||||||
children: [
|
|
||||||
Text("Cartons (${_cartons.length})"),
|
|
||||||
IconButton(
|
|
||||||
icon: Icon(
|
|
||||||
Icons.add_circle,
|
|
||||||
color: primaryColor,
|
|
||||||
),
|
|
||||||
onPressed: () async {
|
|
||||||
Carton _carton = await Navigator.push(
|
|
||||||
context,
|
|
||||||
CupertinoPageRoute(
|
|
||||||
builder: (context) => PackageCartonEditor()),
|
|
||||||
);
|
|
||||||
_addCarton(_carton);
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
final cartonTitleBox = Container(
|
final cartonTitleBox = Container(
|
||||||
child: LocalTitle(
|
child: LocalTitle(
|
||||||
textKey: "boxes.title",
|
textKey: "boxes.title",
|
||||||
@@ -287,26 +265,92 @@ class _CartonEditorState extends State<CartonEditor> {
|
|||||||
color: primaryColor,
|
color: primaryColor,
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
Carton _carton = await Navigator.push(
|
bool isFromPackages = _selectedCartonType == carton_from_packages;
|
||||||
|
if (_user == null && isFromPackages) {
|
||||||
|
showMsgDialog(context, "Error", "Please select customer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_fcsShipment == null && _isNew) {
|
||||||
|
showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double l = double.parse(_lengthController.text, (s) => 0);
|
||||||
|
double w = double.parse(_widthController.text, (s) => 0);
|
||||||
|
double h = double.parse(_heightController.text, (s) => 0);
|
||||||
|
|
||||||
|
Carton carton = Carton();
|
||||||
|
carton.id = _carton.id;
|
||||||
|
carton.cartonType = _selectedCartonType;
|
||||||
|
carton.fcsShipmentID =
|
||||||
|
_isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||||
|
carton.userID = _user?.id;
|
||||||
|
carton.packages =
|
||||||
|
_carton.packages.where((e) => e.isChecked).toList();
|
||||||
|
|
||||||
|
carton.cargoTypes = _carton.cargoTypes;
|
||||||
|
carton.length = l;
|
||||||
|
carton.width = w;
|
||||||
|
carton.height = h;
|
||||||
|
|
||||||
|
carton.deliveryAddress = _carton.deliveryAddress;
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(builder: (context) => PackageCartonEditor()),
|
CupertinoPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
PackageCartonEditor(carton: carton, isNew: _isNew)),
|
||||||
);
|
);
|
||||||
_addCarton(_carton);
|
} catch (e) {
|
||||||
|
showMsgDialog(context, "Error", e.toString());
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final mixTypeBox = Container(
|
final mixTypeBox = Container(
|
||||||
padding: EdgeInsets.only(top: 10),
|
padding: EdgeInsets.only(top: 20),
|
||||||
child: LocalRadioButtons(
|
child: Column(
|
||||||
readOnly: !_isNew,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
values: boxModel.mixTypes,
|
children: [
|
||||||
selectedValue: _selectedMixType,
|
Container(
|
||||||
callback: (v) {
|
padding: EdgeInsets.only(left: 5),
|
||||||
|
child: LocalText(
|
||||||
|
context,
|
||||||
|
"box.mix_type",
|
||||||
|
color: primaryColor,
|
||||||
|
fontSize: 15,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
)),
|
||||||
|
Row(
|
||||||
|
children: boxModel.mixTypes.map((e) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
Radio(
|
||||||
|
value: e,
|
||||||
|
groupValue: _selectedMixType,
|
||||||
|
activeColor: primaryColor,
|
||||||
|
onChanged: (v) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedMixType = v;
|
_selectedMixType = v;
|
||||||
});
|
});
|
||||||
}));
|
},
|
||||||
|
),
|
||||||
|
Text(e),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
final mixcartonTitleBox = Container(
|
final mixcartonTitleBox = Container(
|
||||||
child: LocalTitle(
|
child: LocalTitle(
|
||||||
@@ -316,8 +360,8 @@ class _CartonEditorState extends State<CartonEditor> {
|
|||||||
Icons.add_circle,
|
Icons.add_circle,
|
||||||
color: primaryColor,
|
color: primaryColor,
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () {
|
||||||
Carton _carton = await Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(builder: (context) => MixCartonEditor()),
|
CupertinoPageRoute(builder: (context) => MixCartonEditor()),
|
||||||
);
|
);
|
||||||
@@ -401,7 +445,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
height: 20,
|
height: 20,
|
||||||
),
|
),
|
||||||
_isNew ? createBtn : saveBtn,
|
createBtn,
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 20,
|
height: 20,
|
||||||
),
|
),
|
||||||
@@ -522,78 +566,77 @@ class _CartonEditorState extends State<CartonEditor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_save() async {
|
_save() async {
|
||||||
bool isFromShipment = _selectedCartonType == carton_from_shipments;
|
// bool isFromShipment = _selectedCartonType == carton_from_shipments;
|
||||||
bool isSmallBag = _selectedCartonType == carton_small_bag;
|
// bool isSmallBag = _selectedCartonType == carton_small_bag;
|
||||||
if (_user == null && (isFromShipment || isSmallBag)) {
|
// if (_user == null && (isFromShipment || isSmallBag)) {
|
||||||
showMsgDialog(context, "Error", "Please select customer");
|
// showMsgDialog(context, "Error", "Please select customer");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (_fcsShipment == null && _isNew) {
|
// if (_fcsShipment == null && _isNew) {
|
||||||
showMsgDialog(context, "Error", "Please select FCS shipment");
|
// showMsgDialog(context, "Error", "Please select FCS shipment");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if ((_carton.cargoTypes?.length ?? 0) == 0 &&
|
// if ((_carton.cargoTypes?.length ?? 0) == 0 &&
|
||||||
(isFromShipment || isSmallBag)) {
|
// (isFromShipment || isSmallBag)) {
|
||||||
showMsgDialog(context, "Error", "Expect at least one cargo type");
|
// showMsgDialog(context, "Error", "Expect at least one cargo type");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
double l = double.parse(_lengthController.text, (s) => 0);
|
// double l = double.parse(_lengthController.text, (s) => 0);
|
||||||
double w = double.parse(_widthController.text, (s) => 0);
|
// double w = double.parse(_widthController.text, (s) => 0);
|
||||||
double h = double.parse(_heightController.text, (s) => 0);
|
// double h = double.parse(_heightController.text, (s) => 0);
|
||||||
if ((l <= 0 || w <= 0 || h <= 0) && isFromShipment) {
|
// if ((l <= 0 || w <= 0 || h <= 0) && isFromShipment) {
|
||||||
showMsgDialog(context, "Error", "Invalid dimension");
|
// showMsgDialog(context, "Error", "Invalid dimension");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (_deliveryAddress == null && (isFromShipment || isSmallBag)) {
|
// if (_deliveryAddress == null && (isFromShipment || isSmallBag)) {
|
||||||
showMsgDialog(context, "Error", "Invalid delivery address");
|
// showMsgDialog(context, "Error", "Invalid delivery address");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (isSmallBag && _mixCarton == null && _isNew) {
|
// if (isSmallBag && _mixCarton == null && _isNew) {
|
||||||
showMsgDialog(context, "Error", "Invalid mix carton");
|
// showMsgDialog(context, "Error", "Invalid mix carton");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
Carton carton = Carton();
|
// Carton carton = Carton();
|
||||||
carton.id = _carton.id;
|
// carton.id = _carton.id;
|
||||||
carton.cartonType = _selectedCartonType;
|
// carton.cartonType = _selectedCartonType;
|
||||||
carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
// carton.fcsShipmentID = _isNew ? _fcsShipment.id : _carton.fcsShipmentID;
|
||||||
carton.userID = _user?.id;
|
// carton.userID = _user?.id;
|
||||||
carton.cargoTypes = _carton.cargoTypes;
|
// carton.cargoTypes = _carton.cargoTypes;
|
||||||
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
// carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||||
carton.mixCartonID = _mixCarton?.id;
|
// carton.mixCartonID = _mixCarton?.id;
|
||||||
carton.length = l;
|
// carton.length = l;
|
||||||
carton.width = w;
|
// carton.width = w;
|
||||||
carton.height = h;
|
// carton.height = h;
|
||||||
carton.deliveryAddress = _deliveryAddress;
|
// carton.deliveryAddress = _deliveryAddress;
|
||||||
setState(() {
|
// setState(() {
|
||||||
_isLoading = true;
|
// _isLoading = true;
|
||||||
});
|
// });
|
||||||
try {
|
// try {
|
||||||
CartonModel cartonModel =
|
// CartonModel cartonModel =
|
||||||
Provider.of<CartonModel>(context, listen: false);
|
// Provider.of<CartonModel>(context, listen: false);
|
||||||
if (_isNew) {
|
// if (_isNew) {
|
||||||
await cartonModel.createCarton(carton);
|
// await cartonModel.createCarton(carton);
|
||||||
} else {
|
// } else {
|
||||||
await cartonModel.updateCarton(carton);
|
// await cartonModel.updateCarton(carton);
|
||||||
}
|
// }
|
||||||
|
// Navigator.pop(context, true);
|
||||||
|
// } catch (e) {
|
||||||
|
// showMsgDialog(context, "Error", e.toString());
|
||||||
|
// } finally {
|
||||||
|
// setState(() {
|
||||||
|
// _isLoading = false;
|
||||||
|
// });
|
||||||
|
// }
|
||||||
Navigator.pop(context, true);
|
Navigator.pop(context, true);
|
||||||
} catch (e) {
|
|
||||||
showMsgDialog(context, "Error", e.toString());
|
|
||||||
} finally {
|
|
||||||
setState(() {
|
|
||||||
_isLoading = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isDataChanged() {
|
isDataChanged() {
|
||||||
if (_isNew) {
|
if (_isNew) {
|
||||||
return _fcsShipment != null ||
|
return false;
|
||||||
_user != null ||
|
// return _fcsShipment != null || _user != null;
|
||||||
_cartons.isNotEmpty ||
|
|
||||||
this._mixCartons.isNotEmpty;
|
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:fcs/domain/constants.dart';
|
import 'package:fcs/domain/constants.dart';
|
||||||
|
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||||
import 'package:fcs/domain/entities/carton.dart';
|
import 'package:fcs/domain/entities/carton.dart';
|
||||||
import 'package:fcs/domain/entities/package.dart';
|
import 'package:fcs/domain/entities/package.dart';
|
||||||
import 'package:fcs/domain/vo/delivery_address.dart';
|
import 'package:fcs/domain/vo/delivery_address.dart';
|
||||||
@@ -23,6 +24,7 @@ import 'package:provider/provider.dart';
|
|||||||
import 'cargo_table.dart';
|
import 'cargo_table.dart';
|
||||||
import 'carton_editor.dart';
|
import 'carton_editor.dart';
|
||||||
import 'carton_package_table.dart';
|
import 'carton_package_table.dart';
|
||||||
|
import 'carton_row.dart';
|
||||||
import 'model/carton_model.dart';
|
import 'model/carton_model.dart';
|
||||||
import 'widgets.dart';
|
import 'widgets.dart';
|
||||||
|
|
||||||
@@ -43,8 +45,11 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
TextEditingController _widthController = new TextEditingController();
|
TextEditingController _widthController = new TextEditingController();
|
||||||
TextEditingController _heightController = new TextEditingController();
|
TextEditingController _heightController = new TextEditingController();
|
||||||
TextEditingController _lengthController = new TextEditingController();
|
TextEditingController _lengthController = new TextEditingController();
|
||||||
|
TextEditingController _cartonSizeController = new TextEditingController();
|
||||||
double volumetricRatio = 0;
|
double volumetricRatio = 0;
|
||||||
double shipmentWeight = 0;
|
double shipmentWeight = 0;
|
||||||
|
String selectMixBoxType;
|
||||||
|
List<Carton> _cartons = [];
|
||||||
|
|
||||||
bool isMixBox;
|
bool isMixBox;
|
||||||
bool isFromShipments;
|
bool isFromShipments;
|
||||||
@@ -73,6 +78,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
_widthController.text = _box.width.toString();
|
_widthController.text = _box.width.toString();
|
||||||
_heightController.text = _box.height.toString();
|
_heightController.text = _box.height.toString();
|
||||||
_lengthController.text = _box.length.toString();
|
_lengthController.text = _box.length.toString();
|
||||||
|
_cartonSizeController.text = _box.cartonSizeName ?? "";
|
||||||
_deliveryAddress = _box.deliveryAddress;
|
_deliveryAddress = _box.deliveryAddress;
|
||||||
isMixBox = _box.cartonType == carton_mix_box;
|
isMixBox = _box.cartonType == carton_mix_box;
|
||||||
isFromShipments = _box.cartonType == carton_from_shipments;
|
isFromShipments = _box.cartonType == carton_from_shipments;
|
||||||
@@ -81,6 +87,17 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
isEdiable = !isMixBox &&
|
isEdiable = !isMixBox &&
|
||||||
(isFromPackages || isSmallBag) &&
|
(isFromPackages || isSmallBag) &&
|
||||||
_box.status == carton_packed_status;
|
_box.status == carton_packed_status;
|
||||||
|
selectMixBoxType = _box.mixBoxType ?? "Mix Delivery";
|
||||||
|
_cartons = [
|
||||||
|
Carton(
|
||||||
|
cartonNumber: "A100B-1#1",
|
||||||
|
cargoTypes: [CargoType(name: "General", weight: 12)],
|
||||||
|
userName: "Seven 7"),
|
||||||
|
Carton(
|
||||||
|
cartonNumber: "A100B-1#2",
|
||||||
|
cargoTypes: [CargoType(name: "General", weight: 12)],
|
||||||
|
userName: "Seven 7"),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
_loadPackages() async {
|
_loadPackages() async {
|
||||||
@@ -176,10 +193,10 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
final shipmentWeightBox = DisplayText(
|
final cartonSizeBox = DisplayText(
|
||||||
text: shipmentWeight != null ? shipmentWeight.toStringAsFixed(2) : "",
|
text: _cartonSizeController.text,
|
||||||
labelTextKey: "box.shipment_weight",
|
labelTextKey: "box.carton_size",
|
||||||
iconData: MaterialCommunityIcons.weight,
|
iconData: AntDesign.CodeSandbox,
|
||||||
);
|
);
|
||||||
final cargoTableBox = CargoTable(
|
final cargoTableBox = CargoTable(
|
||||||
cargoTypes: _box.cargoTypes,
|
cargoTypes: _box.cargoTypes,
|
||||||
@@ -190,6 +207,36 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
iconData: MaterialCommunityIcons.package,
|
iconData: MaterialCommunityIcons.package,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final mixTypeBox = Container(
|
||||||
|
padding: EdgeInsets.only(top: 20),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
padding: EdgeInsets.only(left: 5),
|
||||||
|
child: LocalText(
|
||||||
|
context,
|
||||||
|
"box.mix_type",
|
||||||
|
color: primaryColor,
|
||||||
|
fontSize: 15,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
)),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Icon(
|
||||||
|
Icons.check,
|
||||||
|
color: primaryColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(selectMixBoxType)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
return LocalProgress(
|
return LocalProgress(
|
||||||
inAsyncCall: _isLoading,
|
inAsyncCall: _isLoading,
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
@@ -222,7 +269,7 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
),
|
),
|
||||||
body: Padding(
|
body: Padding(
|
||||||
padding: const EdgeInsets.all(10.0),
|
padding: const EdgeInsets.all(10.0),
|
||||||
child: ListView(children: <Widget>[
|
child: ListView(shrinkWrap: true, children: <Widget>[
|
||||||
Center(child: getCartonNumberStatus(context, _box)),
|
Center(child: getCartonNumberStatus(context, _box)),
|
||||||
LocalTitle(textKey: "box.type.title"),
|
LocalTitle(textKey: "box.type.title"),
|
||||||
cartonTypeBox,
|
cartonTypeBox,
|
||||||
@@ -231,6 +278,15 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
isSmallBag ? mixCartonNumberBox : Container(),
|
isSmallBag ? mixCartonNumberBox : Container(),
|
||||||
isMixBox ? Container() : fcsIDBox,
|
isMixBox ? Container() : fcsIDBox,
|
||||||
isMixBox ? Container() : customerNameBox,
|
isMixBox ? Container() : customerNameBox,
|
||||||
|
isMixBox ? mixTypeBox : Container(),
|
||||||
|
isMixBox ? LocalTitle(textKey: "boxes.title") : Container(),
|
||||||
|
isMixBox
|
||||||
|
? Column(
|
||||||
|
children: _getCartons(
|
||||||
|
context,
|
||||||
|
this._cartons,
|
||||||
|
))
|
||||||
|
: Container(),
|
||||||
isFromPackages || isSmallBag
|
isFromPackages || isSmallBag
|
||||||
? CartonPackageTable(
|
? CartonPackageTable(
|
||||||
packages: _box.packages,
|
packages: _box.packages,
|
||||||
@@ -241,8 +297,8 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
...(isFromPackages
|
...(isFromPackages
|
||||||
? [
|
? [
|
||||||
LocalTitle(textKey: "box.dimension"),
|
LocalTitle(textKey: "box.dimension"),
|
||||||
|
cartonSizeBox,
|
||||||
dimBox,
|
dimBox,
|
||||||
shipmentWeightBox,
|
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
isMixBox
|
isMixBox
|
||||||
@@ -263,6 +319,12 @@ class _CartonInfoState extends State<CartonInfo> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Widget> _getCartons(BuildContext context, List<Carton> cartons) {
|
||||||
|
return cartons.map((c) {
|
||||||
|
return CartonRow(box: c);
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
|
|
||||||
_gotoEditor() async {
|
_gotoEditor() async {
|
||||||
bool updated = await Navigator.push<bool>(
|
bool updated = await Navigator.push<bool>(
|
||||||
context,
|
context,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'package:fcs/helpers/theme.dart';
|
|||||||
import 'package:fcs/pages/carton_size/carton_size_list.dart';
|
import 'package:fcs/pages/carton_size/carton_size_list.dart';
|
||||||
import 'package:fcs/pages/carton_size/model/carton_size_model.dart';
|
import 'package:fcs/pages/carton_size/model/carton_size_model.dart';
|
||||||
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
|
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
|
||||||
|
import 'package:fcs/pages/main/util.dart';
|
||||||
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
||||||
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
|
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
|
||||||
import 'package:fcs/pages/widgets/delivery_address_selection.dart';
|
import 'package:fcs/pages/widgets/delivery_address_selection.dart';
|
||||||
@@ -23,10 +24,12 @@ import 'package:provider/provider.dart';
|
|||||||
|
|
||||||
import 'cargo_type_addtion.dart';
|
import 'cargo_type_addtion.dart';
|
||||||
import 'carton_cargo_table.dart';
|
import 'carton_cargo_table.dart';
|
||||||
|
import 'model/carton_model.dart';
|
||||||
|
|
||||||
class PackageCartonEditor extends StatefulWidget {
|
class PackageCartonEditor extends StatefulWidget {
|
||||||
final Carton box;
|
final Carton carton;
|
||||||
PackageCartonEditor({this.box});
|
final bool isNew;
|
||||||
|
PackageCartonEditor({this.carton, this.isNew});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_PackageCartonEditorState createState() => _PackageCartonEditorState();
|
_PackageCartonEditorState createState() => _PackageCartonEditorState();
|
||||||
@@ -37,51 +40,28 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
|||||||
TextEditingController _widthCtl = new TextEditingController();
|
TextEditingController _widthCtl = new TextEditingController();
|
||||||
TextEditingController _heightCtl = new TextEditingController();
|
TextEditingController _heightCtl = new TextEditingController();
|
||||||
|
|
||||||
Carton _box;
|
Carton _carton;
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
bool _isNew;
|
DeliveryAddress _deliveryAddress = new DeliveryAddress();
|
||||||
double volumetricRatio = 0;
|
|
||||||
double shipmentWeight = 0;
|
List<CargoType> _cargoTypes = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
if (widget.isNew) {
|
||||||
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
|
_carton = widget.carton;
|
||||||
.rate
|
_lengthCtl.text = "0";
|
||||||
.volumetricRatio;
|
_widthCtl.text = "0";
|
||||||
|
_heightCtl.text = "0";
|
||||||
if (widget.box != null) {
|
|
||||||
_box = widget.box;
|
|
||||||
_isNew = false;
|
|
||||||
_lengthCtl.text = _box.length.toString();
|
|
||||||
_widthCtl.text = _box.width.toString();
|
|
||||||
_heightCtl.text = _box.height.toString();
|
|
||||||
} else {
|
} else {
|
||||||
var shipmentModel =
|
_carton = widget.carton;
|
||||||
Provider.of<DeliveryAddressModel>(context, listen: false);
|
_cargoTypes = List.from(widget.carton.cargoTypes);
|
||||||
|
_lengthCtl.text = _carton.length.toString();
|
||||||
_isNew = true;
|
_widthCtl.text = _carton.width.toString();
|
||||||
_box = Carton(cargoTypes: []);
|
_heightCtl.text = _carton.height.toString();
|
||||||
_box.deliveryAddress = shipmentModel.defalutAddress;
|
_deliveryAddress = _carton.deliveryAddress;
|
||||||
|
|
||||||
_lengthCtl.text = "12";
|
|
||||||
_widthCtl.text = "12";
|
|
||||||
_heightCtl.text = "12";
|
|
||||||
}
|
}
|
||||||
_lengthCtl.addListener(_calShipmentWeight);
|
|
||||||
_widthCtl.addListener(_calShipmentWeight);
|
|
||||||
_heightCtl.addListener(_calShipmentWeight);
|
|
||||||
_calShipmentWeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
_calShipmentWeight() {
|
|
||||||
double l = double.parse(_lengthCtl.text, (s) => 0);
|
|
||||||
double w = double.parse(_widthCtl.text, (s) => 0);
|
|
||||||
double h = double.parse(_heightCtl.text, (s) => 0);
|
|
||||||
setState(() {
|
|
||||||
shipmentWeight = (l * w * h / volumetricRatio).ceilToDouble();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -131,14 +111,15 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
|||||||
CupertinoPageRoute(builder: (context) => CargoTypeAddition()));
|
CupertinoPageRoute(builder: (context) => CargoTypeAddition()));
|
||||||
if (cargos == null) return;
|
if (cargos == null) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_box.cargoTypes.clear();
|
_cargoTypes.clear();
|
||||||
_box.cargoTypes.addAll(cargos);
|
_cargoTypes.addAll(cargos);
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
final cargoTableBox = CargoTable(
|
final cargoTableBox = CargoTable(
|
||||||
cargoTypes: _box.cargoTypes,
|
isNew: widget.isNew,
|
||||||
|
cargoTypes: _cargoTypes,
|
||||||
onAdd: (c) => _addCargo(c),
|
onAdd: (c) => _addCargo(c),
|
||||||
onRemove: (c) => _removeCargo(c),
|
onRemove: (c) => _removeCargo(c),
|
||||||
);
|
);
|
||||||
@@ -159,7 +140,7 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
|||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
title: LocalText(
|
title: LocalText(
|
||||||
context,
|
context,
|
||||||
_isNew ? "boxes.create.title" : "box.edit.title",
|
widget.isNew ? "boxes.create.title" : "box.edit.title",
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
color: primaryColor,
|
color: primaryColor,
|
||||||
),
|
),
|
||||||
@@ -175,19 +156,19 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
|||||||
dimBox,
|
dimBox,
|
||||||
LocalTitle(textKey: "box.delivery_address"),
|
LocalTitle(textKey: "box.delivery_address"),
|
||||||
DefaultDeliveryAddress(
|
DefaultDeliveryAddress(
|
||||||
deliveryAddress: _box.deliveryAddress,
|
deliveryAddress: _deliveryAddress,
|
||||||
labelKey: "box.delivery_address",
|
labelKey: "box.delivery_address",
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
|
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) => DeliveryAddressSelection(
|
builder: (context) => DeliveryAddressSelection(
|
||||||
deliveryAddress: _box.deliveryAddress,
|
deliveryAddress: _deliveryAddress,
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
if (d == null) return;
|
if (d == null) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_box.deliveryAddress = d;
|
_deliveryAddress = d;
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
@@ -280,24 +261,64 @@ class _PackageCartonEditorState extends State<PackageCartonEditor> {
|
|||||||
_addCargo(CargoType cargo) {
|
_addCargo(CargoType cargo) {
|
||||||
if (cargo == null) return;
|
if (cargo == null) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_box.cargoTypes.remove(cargo);
|
_cargoTypes.remove(cargo);
|
||||||
_box.cargoTypes.add(cargo);
|
_cargoTypes.add(cargo);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_removeCargo(CargoType cargo) {
|
_removeCargo(CargoType cargo) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_box.cargoTypes.remove(cargo);
|
_cargoTypes.remove(cargo);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_creatCarton() {
|
_creatCarton() async {
|
||||||
// double l = double.parse(_lengthCtl.text, (s) => 0);
|
if ((_cargoTypes?.length ?? 0) == 0) {
|
||||||
// double w = double.parse(_widthCtl.text, (s) => 0);
|
showMsgDialog(context, "Error", "Expect at least one cargo type");
|
||||||
// double h = double.parse(_heightCtl.text, (s) => 0);
|
return;
|
||||||
// _box.length = l;
|
}
|
||||||
// _box.width = w;
|
double l = double.parse(_lengthCtl.text, (s) => 0);
|
||||||
// _box.height = h;
|
double w = double.parse(_widthCtl.text, (s) => 0);
|
||||||
// Navigator.pop(context, _box);
|
double h = double.parse(_heightCtl.text, (s) => 0);
|
||||||
|
if ((l <= 0 || w <= 0 || h <= 0)) {
|
||||||
|
showMsgDialog(context, "Error", "Invalid dimension");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_deliveryAddress == null) {
|
||||||
|
showMsgDialog(context, "Error", "Invalid delivery address");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Carton carton = Carton();
|
||||||
|
carton.id = _carton.id;
|
||||||
|
carton.cartonType = _carton.cartonType;
|
||||||
|
carton.fcsShipmentID = _carton.fcsShipmentID;
|
||||||
|
carton.userID = _carton.userID;
|
||||||
|
carton.cargoTypes = _cargoTypes;
|
||||||
|
carton.packages = _carton.packages.where((e) => e.isChecked).toList();
|
||||||
|
// carton.cartonSizeID = selectedCatonSize?.id;
|
||||||
|
carton.length = l;
|
||||||
|
carton.width = w;
|
||||||
|
carton.height = h;
|
||||||
|
carton.deliveryAddress = _deliveryAddress;
|
||||||
|
setState(() {
|
||||||
|
_isLoading = true;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
CartonModel cartonModel =
|
||||||
|
Provider.of<CartonModel>(context, listen: false);
|
||||||
|
if (widget.isNew) {
|
||||||
|
await cartonModel.createCarton(carton);
|
||||||
|
} else {
|
||||||
|
await cartonModel.updateCarton(carton);
|
||||||
|
}
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
} catch (e) {
|
||||||
|
showMsgDialog(context, "Error", e.toString());
|
||||||
|
} finally {
|
||||||
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user