check null safety
This commit is contained in:
@@ -33,7 +33,7 @@ class _CargoTableState extends State<CargoTable> {
|
||||
cargoTypes = widget.cargoTypes;
|
||||
if (!widget.isNew!) {
|
||||
totalWeight =
|
||||
cargoTypes!.fold(0, (previous, current) => previous + current.weight!);
|
||||
cargoTypes!.fold(0, (previous, current) => previous + current.weight);
|
||||
}
|
||||
|
||||
super.initState();
|
||||
@@ -42,7 +42,7 @@ class _CargoTableState extends State<CargoTable> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
print("Cargotypes:${cargoTypes!.length}");
|
||||
|
||||
|
||||
return SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: MyDataTable(
|
||||
@@ -86,7 +86,7 @@ class _CargoTableState extends State<CargoTable> {
|
||||
cells: [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
c.name ??'',
|
||||
c.name ?? '',
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
@@ -144,7 +144,7 @@ class _CargoTableState extends State<CargoTable> {
|
||||
context: context,
|
||||
builder: (_) => DialogInput(
|
||||
label: "cargo.weight",
|
||||
value: c.weight!.toStringAsFixed(2)));
|
||||
value: c.weight.toStringAsFixed(2)));
|
||||
|
||||
if (_t == null) return;
|
||||
setState(() {
|
||||
@@ -162,7 +162,7 @@ class _CargoTableState extends State<CargoTable> {
|
||||
borderRadius: BorderRadius.all(Radius.circular(5.0)),
|
||||
),
|
||||
child: Text(
|
||||
c.weight == null ? "0.00" : c.weight!.toStringAsFixed(2),
|
||||
c.weight == null ? "0.00" : c.weight.toStringAsFixed(2),
|
||||
style: textStyle),
|
||||
),
|
||||
),
|
||||
@@ -252,11 +252,10 @@ class _CargoTableState extends State<CargoTable> {
|
||||
}
|
||||
|
||||
CargoType? autoCalWeight(List<CargoType> cargoTypes, double total) {
|
||||
if ((cargoTypes?.length ?? 0) == 0 || total == 0) return null;
|
||||
List<CargoType> noWeight = cargoTypes.where((c) => c.weight == 0).toList();
|
||||
if (noWeight.length != 1) return null;
|
||||
|
||||
var _existing =
|
||||
double _existing =
|
||||
cargoTypes.fold(0, (previous, current) => previous + current.weight);
|
||||
|
||||
noWeight[0].weight = total - _existing;
|
||||
|
||||
Reference in New Issue
Block a user