Merge branch 'master' of https://git.mokkon.com/sainw/fcs
This commit is contained in:
@@ -6,11 +6,12 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'cargo_type_editor.dart';
|
||||
import 'total_weight_edit.dart';
|
||||
|
||||
typedef OnAdd(CargoType cargoType);
|
||||
typedef OnRemove(CargoType cargoType);
|
||||
|
||||
class CargoTable extends StatelessWidget {
|
||||
class CargoTable extends StatefulWidget {
|
||||
final List<CargoType> cargoTypes;
|
||||
final OnAdd onAdd;
|
||||
final OnRemove onRemove;
|
||||
@@ -18,6 +19,12 @@ class CargoTable extends StatelessWidget {
|
||||
const CargoTable({Key key, this.cargoTypes, this.onAdd, this.onRemove})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_CargoTableState createState() => _CargoTableState();
|
||||
}
|
||||
|
||||
class _CargoTableState extends State<CargoTable> {
|
||||
double totalWeight = 0;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MyDataTable(
|
||||
@@ -43,12 +50,14 @@ class CargoTable extends StatelessWidget {
|
||||
}
|
||||
|
||||
List<MyDataRow> getCargoRows(BuildContext context) {
|
||||
if (cargoTypes == null) {
|
||||
if (widget.cargoTypes == null) {
|
||||
return [];
|
||||
}
|
||||
double total = 0;
|
||||
var rows = cargoTypes.map((c) {
|
||||
total += c.weight;
|
||||
|
||||
double _total = 0;
|
||||
var rows = widget.cargoTypes.map((c) {
|
||||
_total += c.weight;
|
||||
|
||||
return MyDataRow(
|
||||
onSelectChanged: (bool selected) async {
|
||||
CargoType cargo = await Navigator.push<CargoType>(
|
||||
@@ -57,7 +66,7 @@ class CargoTable extends StatelessWidget {
|
||||
builder: (context) => CargoTypeEditor(
|
||||
cargo: c,
|
||||
)));
|
||||
if (onAdd != null) onAdd(cargo);
|
||||
if (widget.onAdd != null) widget.onAdd(cargo);
|
||||
},
|
||||
cells: [
|
||||
MyDataCell(new Text(
|
||||
@@ -68,9 +77,8 @@ class CargoTable extends StatelessWidget {
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(c.weight == null ? "0" : c.weight.toString(),
|
||||
style: textStyle),
|
||||
onRemove == null
|
||||
Text(c.weight.toStringAsFixed(2), style: textStyle),
|
||||
widget.onRemove == null
|
||||
? SizedBox(
|
||||
width: 50,
|
||||
)
|
||||
@@ -80,7 +88,93 @@ class CargoTable extends StatelessWidget {
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
if (onRemove != null) onRemove(c);
|
||||
if (widget.onRemove != null) widget.onRemove(c);
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
|
||||
var totalRow = MyDataRow(
|
||||
onSelectChanged: (bool selected) async {
|
||||
double _t = await Navigator.of(context).push<double>(CupertinoPageRoute(
|
||||
builder: (context) => TotalWeightEdit(totalWeight: totalWeight)));
|
||||
if (_t == null) return;
|
||||
setState(() {
|
||||
totalWeight = _t;
|
||||
});
|
||||
},
|
||||
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(totalWeight.toStringAsFixed(2),
|
||||
style: TextStyle(fontWeight: FontWeight.bold))),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
rows.add(totalRow);
|
||||
return rows;
|
||||
}
|
||||
|
||||
double getRemainBalance(double total) {
|
||||
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);
|
||||
})
|
||||
],
|
||||
),
|
||||
@@ -106,7 +200,7 @@ class CargoTable extends StatelessWidget {
|
||||
padding: const EdgeInsets.only(right: 48.0),
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(total.toString(),
|
||||
child: Text(total.toStringAsFixed(2),
|
||||
style: TextStyle(fontWeight: FontWeight.bold))),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user