null safety

This commit is contained in:
Phaung Phaung
2021-09-10 14:29:55 +06:30
parent 5a313d641e
commit d862049b45
22 changed files with 93 additions and 51 deletions

View File

@@ -31,8 +31,8 @@ class _CargoEditorState extends State<CargoEditor> {
super.initState();
if (widget.cargo != null) {
_cargo = widget.cargo!;
_descController.text = _cargo.name;
_rateController.text = _cargo.rate.toStringAsFixed(2);
_descController.text = _cargo.name ?? '';
_rateController.text = _cargo.rate?.toStringAsFixed(2) ?? '';
} else {
_isNew = true;
}
@@ -138,7 +138,8 @@ class _CargoEditorState extends State<CargoEditor> {
try {
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
await shipmentRateModel.deleteCargoType(this._cargo.id);
if(this._cargo.id != null)
await shipmentRateModel.deleteCargoType(this._cargo.id!);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -75,8 +75,8 @@ class _CargoTypeListState extends State<CargoTypeList> {
)));
},
child: Container(
child: _row(cargo.name,
"\$ " + cargo.rate.toStringAsFixed(2), 'per pound'),
child: _row(cargo.name?? '',
"\$ " + cargo.rate!.toStringAsFixed(2), 'per pound'),
),
);
}),

View File

@@ -33,10 +33,10 @@ class _CustomEditorState extends State<CustomEditor> {
super.initState();
if (widget.custom != null) {
_custom = widget.custom!;
_productController.text = _custom.name;
_feeController.text = _custom.customDutyFee.toStringAsFixed(2);
_productController.text = _custom.name ?? '';
_feeController.text = _custom.customDutyFee?.toStringAsFixed(2) ?? '';
_shipmentRateController.text =
_custom.rate == null ? "" : _custom.rate.toStringAsFixed(2);
_custom.rate == null ? "" : _custom.rate?.toStringAsFixed(2) ?? '';
} else {
_isNew = true;
}
@@ -154,7 +154,8 @@ class _CustomEditorState extends State<CustomEditor> {
try {
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
await shipmentRateModel.deleteCustomDuty(this._custom.id);
if(this._custom.id != null)
await shipmentRateModel.deleteCustomDuty(this._custom.id!);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -81,11 +81,15 @@ class _CustomListState extends State<CustomList> {
},
child: Container(
child: _row(
custom.name,
"Custom Fee \$ " + custom.customDutyFee.toStringAsFixed(2),
custom.name ?? '',
custom.customDutyFee == null
? ""
: "Custom Fee \$ " +
custom.customDutyFee!.toStringAsFixed(2),
custom.rate == null
? ""
: "Shipment rate \$ " + custom.rate.toStringAsFixed(2)),
: "Shipment rate \$ " +
custom.rate!.toStringAsFixed(2)),
),
);
}),

View File

@@ -4,6 +4,7 @@ import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
typedef SelectionCallback(CustomDuty custom);

View File

@@ -1,5 +1,4 @@
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/domain/entities/custom_duty.dart';
import 'package:fcs/domain/entities/discount_by_weight.dart';
import 'package:fcs/domain/entities/rate.dart';
import 'package:fcs/helpers/theme.dart';
@@ -186,7 +185,7 @@ class _ShipmentRatesState extends State<ShipmentRates> {
return cargos.map((cargo) {
return Container(
child: _row(
cargo.name, "\$ " + cargo.rate.toStringAsFixed(2), 'per pound'),
cargo.name ?? '', "\$ " + cargo.rate!.toStringAsFixed(2), 'per pound'),
);
}).toList();
}
@@ -194,7 +193,7 @@ class _ShipmentRatesState extends State<ShipmentRates> {
List<Widget> getCustonWidget(List<CargoType> customs) {
return customs.map((c) {
return Container(
child: _row(c.name, "\$ " + c.customDutyFee.toStringAsFixed(2), ''),
child: _row(c.name ?? '', "\$ " + c.customDutyFee!.toStringAsFixed(2), ''),
);
}).toList();
}

View File

@@ -11,6 +11,7 @@ import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
import 'package:provider/provider.dart';
class ShipmentRatesCal extends StatefulWidget {
@@ -61,11 +62,11 @@ class _ShipmentRatesCalState extends State<ShipmentRatesCal> {
var amount = box.calAmount(rate);
var shipmentWeight = box.getShipmentWeight(rate.volumetricRatio);
var effectiveWeight =
_cargoType.weight > shipmentWeight ? _cargoType.weight : shipmentWeight;
_cargoType.weight! > shipmentWeight ? _cargoType.weight : shipmentWeight;
setState(() {
_deliveryFee =
effectiveWeight > rate.freeDeliveryWeight ? 0 : rate.deliveryFee;
effectiveWeight! > rate.freeDeliveryWeight ? 0 : rate.deliveryFee;
_amount = amount == null ? 0 : amount + _deliveryFee;
_shipmentWeight = shipmentWeight.toDouble();
});