check null safety

This commit is contained in:
tzw
2021-09-10 16:33:52 +06:30
parent 3eacbef117
commit d8c86a512b
46 changed files with 275 additions and 304 deletions

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,9 +1,9 @@
import 'package:fcs/domain/entities/custom_duty.dart';
import 'package:fcs/domain/vo/delivery_address.dart';
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_icons_null_safety/flutter_icons_null_safety.dart';
typedef SelectionCallback(CustomDuty custom);

View File

@@ -143,7 +143,7 @@ class _DiscountByWeightEditorState extends State<DiscountByWeightEditor> {
var shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
await shipmentRateModel
.deleteDiscountByWeight(this._discountByWeight.id);
.deleteDiscountByWeight(this._discountByWeight.id!);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -2,7 +2,6 @@ import 'dart:async';
import 'package:fcs/data/services/services.dart';
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/pages/main/model/base_model.dart';
@@ -11,12 +10,12 @@ import 'package:logging/logging.dart';
class ShipmentRateModel extends BaseModel {
final log = Logger('ShipmentRateModel');
StreamSubscription<Rate> listener;
Rate rate;
StreamSubscription<Rate>? listener;
late Rate rate;
void initUser(user) {
super.initUser(user);
if (listener != null) listener.cancel();
if (listener != null) listener!.cancel();
listener = Services.instance.rateService.getRateStream().listen((rate) {
this.rate = rate;
notifyListeners();
@@ -25,7 +24,7 @@ class ShipmentRateModel extends BaseModel {
@override
logout() async {
if (listener != null) await listener.cancel();
if (listener != null) await listener!.cancel();
}
// Rate
@@ -51,12 +50,12 @@ class ShipmentRateModel extends BaseModel {
//CustomDuty
Future<void> addCustomDuty(CargoType customDuty) {
customDuty.isCutomDuty=true;
customDuty.isCutomDuty = true;
return Services.instance.rateService.createCargoType(customDuty);
}
Future<void> updateCustomDuty(CargoType customDuty) {
customDuty.isCutomDuty=true;
customDuty.isCutomDuty = true;
return Services.instance.rateService.updateCargoType(customDuty);
}

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';
@@ -185,8 +184,8 @@ class _ShipmentRatesState extends State<ShipmentRates> {
List<Widget> getCargoWidget(List<CargoType> cargos) {
return cargos.map((cargo) {
return Container(
child: _row(
cargo.name, "\$ " + cargo.rate.toStringAsFixed(2), 'per pound'),
child: _row(cargo.name ?? "", "\$ " + cargo.rate.toStringAsFixed(2),
'per pound'),
);
}).toList();
}
@@ -194,7 +193,8 @@ 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_icons_null_safety/flutter_icons_null_safety.dart';
import 'package:provider/provider.dart';
class ShipmentRatesCal extends StatefulWidget {

View File

@@ -35,12 +35,11 @@ class _ShipmentRatesEditState extends State<ShipmentRatesEdit> {
Provider.of<ShipmentRateModel>(context, listen: false);
rate = shipmentRateModel.rate;
_minWeight.text = rate.freeDeliveryWeight?.toStringAsFixed(2) ?? "";
_deliveryFee.text = rate.deliveryFee?.toStringAsFixed(2) ?? "";
_volumetricRatio.text = rate.volumetricRatio?.toStringAsFixed(2) ?? "";
_diffDiscountWeight.text =
rate.diffDiscountWeight?.toStringAsFixed(2) ?? "";
_diffWeightRate.text = rate.diffWeightRate?.toStringAsFixed(2) ?? "";
_minWeight.text = rate.freeDeliveryWeight.toStringAsFixed(2);
_deliveryFee.text = rate.deliveryFee.toStringAsFixed(2);
_volumetricRatio.text = rate.volumetricRatio.toStringAsFixed(2);
_diffDiscountWeight.text = rate.diffDiscountWeight.toStringAsFixed(2);
_diffWeightRate.text = rate.diffWeightRate.toStringAsFixed(2);
}
@override