add prompt confirmation and update carton
This commit is contained in:
@@ -41,10 +41,17 @@ class _CargoTableState extends State<CargoTable> {
|
||||
),
|
||||
),
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context,
|
||||
"cargo.weight",
|
||||
color: Colors.grey,
|
||||
label: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 50),
|
||||
child: LocalText(
|
||||
context,
|
||||
"cargo.weight",
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -58,50 +65,24 @@ class _CargoTableState extends State<CargoTable> {
|
||||
}
|
||||
List<String> _list = [];
|
||||
List<String> _types = [];
|
||||
double _total = 0;
|
||||
|
||||
var rows = widget.cargoTypes.map((c) {
|
||||
_total += c.weight;
|
||||
return MyDataRow(
|
||||
onSelectChanged: (bool selected) async {
|
||||
if (this.totalWeight <= 0) {
|
||||
showMsgDialog(context, "Error", "Please insert total weight");
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
onSelectChanged: (bool selected) async {},
|
||||
cells: [
|
||||
MyDataCell(new Text(
|
||||
c.name == null ? "" : c.name,
|
||||
style: textStyle,
|
||||
MyDataCell(Row(
|
||||
children: [
|
||||
new Text(
|
||||
c.name == null ? "" : c.name,
|
||||
style: textStyle,
|
||||
),
|
||||
new Text(
|
||||
c.qty == null ? "" : " x ${c.qty.toString()}",
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
],
|
||||
)),
|
||||
MyDataCell(
|
||||
Row(
|
||||
@@ -153,13 +134,35 @@ class _CargoTableState extends State<CargoTable> {
|
||||
if (_t == null) return;
|
||||
setState(() {
|
||||
totalWeight = _t;
|
||||
remainingWeight = _t;
|
||||
this.remainingWeight = this.totalWeight - _total;
|
||||
widget.cargoTypes.forEach((c) {
|
||||
if (c.qty == null) {
|
||||
this._cargos.add(c);
|
||||
}
|
||||
});
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(7.0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: primaryColor),
|
||||
border: Border.all(color: Colors.grey),
|
||||
borderRadius: BorderRadius.all(Radius.circular(5.0)),
|
||||
),
|
||||
child: Text(totalWeight.toStringAsFixed(2),
|
||||
@@ -178,78 +181,4 @@ class _CargoTableState extends State<CargoTable> {
|
||||
double _r = this.totalWeight < total ? 0 : this.totalWeight - total;
|
||||
return _r;
|
||||
}
|
||||
|
||||
List<MyDataRow> _getCargoRows(BuildContext context) {
|
||||
if (widget.cargoTypes == null) {
|
||||
return [];
|
||||
}
|
||||
double total = 0;
|
||||
var rows = widget.cargoTypes.map((c) {
|
||||
total += c.weight;
|
||||
return MyDataRow(
|
||||
onSelectChanged: (bool selected) async {
|
||||
CargoType cargo = await Navigator.push<CargoType>(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CargoTypeEditor(
|
||||
cargo: c,
|
||||
)));
|
||||
if (widget.onAdd != null) widget.onAdd(cargo);
|
||||
},
|
||||
cells: [
|
||||
MyDataCell(new Text(
|
||||
c.name == null ? "" : c.name,
|
||||
style: textStyle,
|
||||
)),
|
||||
MyDataCell(
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(c.weight == null ? "0" : c.weight.toStringAsFixed(2),
|
||||
style: textStyle),
|
||||
widget.onRemove == null
|
||||
? SizedBox(
|
||||
width: 50,
|
||||
)
|
||||
: IconButton(
|
||||
icon: Icon(
|
||||
Icons.remove_circle,
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
if (widget.onRemove != null) widget.onRemove(c);
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
|
||||
var totalRow = MyDataRow(
|
||||
onSelectChanged: (bool selected) {},
|
||||
cells: [
|
||||
MyDataCell(Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: LocalText(
|
||||
context,
|
||||
"shipment.cargo.total",
|
||||
color: Colors.black87,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
)),
|
||||
MyDataCell(
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 48.0),
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(total.toStringAsFixed(2),
|
||||
style: TextStyle(fontWeight: FontWeight.bold))),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
rows.add(totalRow);
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user