null safety
This commit is contained in:
@@ -13,11 +13,11 @@ typedef OnAdd(CargoType cargoType);
|
||||
typedef OnRemove(CargoType cargoType);
|
||||
|
||||
class CargoTable extends StatefulWidget {
|
||||
final List<CargoType> cargoTypes;
|
||||
final OnAdd onAdd;
|
||||
final OnRemove onRemove;
|
||||
final List<CargoType>? cargoTypes;
|
||||
final OnAdd? onAdd;
|
||||
final OnRemove? onRemove;
|
||||
|
||||
const CargoTable({Key key, this.cargoTypes, this.onAdd, this.onRemove})
|
||||
const CargoTable({Key? key, this.cargoTypes, this.onAdd, this.onRemove})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
@@ -67,15 +67,15 @@ class _CargoTableState extends State<CargoTable> {
|
||||
List<String> _types = [];
|
||||
double _total = 0;
|
||||
|
||||
var rows = widget.cargoTypes.map((c) {
|
||||
_total += c.weight;
|
||||
var rows = widget.cargoTypes!.map((c) {
|
||||
_total += c.weight!;
|
||||
return MyDataRow(
|
||||
onSelectChanged: (bool selected) async {},
|
||||
cells: [
|
||||
MyDataCell(Row(
|
||||
children: [
|
||||
new Text(
|
||||
c.name == null ? "" : c.name,
|
||||
c.name ?? "",
|
||||
style: textStyle,
|
||||
),
|
||||
new Text(
|
||||
@@ -88,7 +88,7 @@ class _CargoTableState extends State<CargoTable> {
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text(c.weight.toStringAsFixed(2), style: textStyle),
|
||||
Text(c.weight!.toStringAsFixed(2), style: textStyle),
|
||||
widget.onRemove == null
|
||||
? SizedBox(
|
||||
width: 50,
|
||||
@@ -99,7 +99,7 @@ class _CargoTableState extends State<CargoTable> {
|
||||
color: primaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
if (widget.onRemove != null) widget.onRemove(c);
|
||||
if (widget.onRemove != null) widget.onRemove!(c);
|
||||
})
|
||||
],
|
||||
),
|
||||
@@ -127,7 +127,7 @@ class _CargoTableState extends State<CargoTable> {
|
||||
alignment: Alignment.centerRight,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
double _t = await Navigator.of(context).push<double>(
|
||||
double? _t = await Navigator.of(context).push<double>(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
TotalWeightEdit(totalWeight: totalWeight)));
|
||||
@@ -135,21 +135,21 @@ class _CargoTableState extends State<CargoTable> {
|
||||
setState(() {
|
||||
totalWeight = _t;
|
||||
this.remainingWeight = this.totalWeight - _total;
|
||||
widget.cargoTypes.forEach((c) {
|
||||
widget.cargoTypes!.forEach((c) {
|
||||
if (c.qty == null) {
|
||||
this._cargos.add(c);
|
||||
}
|
||||
});
|
||||
this._cargos.forEach((c) {
|
||||
_list.add(c.name);
|
||||
_list.add(c.name!);
|
||||
});
|
||||
widget.cargoTypes.forEach((c) {
|
||||
_types.add(c.name);
|
||||
widget.cargoTypes!.forEach((c) {
|
||||
_types.add(c.name!);
|
||||
});
|
||||
if (this._cargos.length == widget.cargoTypes.length - 1) {
|
||||
if (this._cargos.length == widget.cargoTypes!.length - 1) {
|
||||
_types.forEach((t) {
|
||||
if (!_list.contains(t)) {
|
||||
widget.cargoTypes.forEach((c) {
|
||||
widget.cargoTypes!.forEach((c) {
|
||||
if (c.name == t) {
|
||||
c.weight = this.remainingWeight;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user