2020-10-20 06:19:10 +06:30
|
|
|
import 'package:fcs/domain/entities/cargo_type.dart';
|
|
|
|
|
import 'package:fcs/helpers/theme.dart';
|
2020-12-04 17:28:21 +06:30
|
|
|
import 'package:fcs/pages/main/util.dart';
|
2020-10-20 06:19:10 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/my_data_table.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
import 'cargo_type_editor.dart';
|
2020-12-02 20:55:00 +06:30
|
|
|
import 'total_weight_edit.dart';
|
2020-10-20 06:19:10 +06:30
|
|
|
|
|
|
|
|
typedef OnAdd(CargoType cargoType);
|
|
|
|
|
typedef OnRemove(CargoType cargoType);
|
|
|
|
|
|
2020-12-02 20:55:00 +06:30
|
|
|
class CargoTable extends StatefulWidget {
|
2020-10-20 06:19:10 +06:30
|
|
|
final List<CargoType> cargoTypes;
|
|
|
|
|
final OnAdd onAdd;
|
|
|
|
|
final OnRemove onRemove;
|
|
|
|
|
|
|
|
|
|
const CargoTable({Key key, this.cargoTypes, this.onAdd, this.onRemove})
|
|
|
|
|
: super(key: key);
|
|
|
|
|
|
2020-12-02 20:55:00 +06:30
|
|
|
@override
|
|
|
|
|
_CargoTableState createState() => _CargoTableState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _CargoTableState extends State<CargoTable> {
|
|
|
|
|
double totalWeight = 0;
|
2020-12-04 17:28:21 +06:30
|
|
|
List<CargoType> _cargos = [];
|
|
|
|
|
double remainingWeight = 0;
|
2020-12-08 20:24:15 +06:30
|
|
|
|
2020-10-20 06:19:10 +06:30
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-12-08 20:24:15 +06:30
|
|
|
remainingWeight =
|
|
|
|
|
widget.cargoTypes.length == 0 ? this.totalWeight : remainingWeight;
|
|
|
|
|
this._cargos = widget.cargoTypes.length == 0 ? [] : this._cargos;
|
|
|
|
|
|
2020-10-20 06:19:10 +06:30
|
|
|
return MyDataTable(
|
|
|
|
|
headingRowHeight: 40,
|
|
|
|
|
columns: [
|
|
|
|
|
MyDataColumn(
|
|
|
|
|
label: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
"cargo.type",
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
MyDataColumn(
|
2020-12-08 20:24:15 +06:30
|
|
|
label: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
"cargo.weight",
|
|
|
|
|
color: Colors.grey,
|
2020-10-20 06:19:10 +06:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
rows: getCargoRows(context),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<MyDataRow> getCargoRows(BuildContext context) {
|
2020-12-02 20:55:00 +06:30
|
|
|
if (widget.cargoTypes == null) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2020-12-07 17:18:26 +06:30
|
|
|
List<String> _list = [];
|
|
|
|
|
List<String> _types = [];
|
2020-12-02 20:55:00 +06:30
|
|
|
|
|
|
|
|
var rows = widget.cargoTypes.map((c) {
|
|
|
|
|
return MyDataRow(
|
2020-12-08 20:24:15 +06:30
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-12-02 20:55:00 +06:30
|
|
|
cells: [
|
2020-12-07 17:18:26 +06:30
|
|
|
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),
|
|
|
|
|
),
|
|
|
|
|
],
|
2020-12-02 20:55:00 +06:30
|
|
|
)),
|
|
|
|
|
MyDataCell(
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
children: [
|
2020-12-08 20:24:15 +06:30
|
|
|
Text(c.weight == null ? "0.00" : c.weight.toStringAsFixed(2),
|
|
|
|
|
style: textStyle),
|
2020-12-02 20:55:00 +06:30
|
|
|
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(
|
2020-12-07 17:18:26 +06:30
|
|
|
onSelectChanged: (bool selected) {},
|
2020-12-02 20:55:00 +06:30
|
|
|
cells: [
|
|
|
|
|
MyDataCell(Align(
|
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
|
child: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
"shipment.cargo.total",
|
|
|
|
|
color: Colors.black87,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
)),
|
|
|
|
|
MyDataCell(
|
|
|
|
|
Padding(
|
2020-12-07 17:18:26 +06:30
|
|
|
padding: const EdgeInsets.only(right: 40.0),
|
2020-12-02 20:55:00 +06:30
|
|
|
child: Align(
|
|
|
|
|
alignment: Alignment.centerRight,
|
2020-12-07 17:18:26 +06:30
|
|
|
child: InkWell(
|
|
|
|
|
onTap: () async {
|
|
|
|
|
double _t = await Navigator.of(context).push<double>(
|
|
|
|
|
CupertinoPageRoute(
|
|
|
|
|
builder: (context) =>
|
|
|
|
|
TotalWeightEdit(totalWeight: totalWeight)));
|
|
|
|
|
if (_t == null) return;
|
|
|
|
|
setState(() {
|
|
|
|
|
totalWeight = _t;
|
2020-12-08 20:24:15 +06:30
|
|
|
remainingWeight = totalWeight;
|
2020-12-07 17:18:26 +06:30
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.all(7.0),
|
|
|
|
|
decoration: BoxDecoration(
|
2020-12-08 20:24:15 +06:30
|
|
|
border: Border.all(color: primaryColor),
|
2020-12-07 17:18:26 +06:30
|
|
|
borderRadius: BorderRadius.all(Radius.circular(5.0)),
|
|
|
|
|
),
|
|
|
|
|
child: Text(totalWeight.toStringAsFixed(2),
|
|
|
|
|
style: TextStyle(fontWeight: FontWeight.bold)),
|
|
|
|
|
),
|
|
|
|
|
)),
|
2020-12-02 20:55:00 +06:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
rows.add(totalRow);
|
|
|
|
|
return rows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double getRemainBalance(double total) {
|
|
|
|
|
double _r = this.totalWeight < total ? 0 : this.totalWeight - total;
|
|
|
|
|
return _r;
|
|
|
|
|
}
|
2020-12-08 20:24:15 +06:30
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2020-10-20 06:19:10 +06:30
|
|
|
}
|