null safety

This commit is contained in:
phyothandar
2021-09-10 17:14:59 +06:30
parent 4f7aa1b252
commit 2c95ec7600
21 changed files with 54 additions and 51 deletions

View File

@@ -28,7 +28,7 @@ class Invoice {
List<CustomDuty> customDuties;
List<Carton> cartons;
List<CargoType> cargoTypes;
List<Shipment> shipments;
List<Shipment?>? shipments;
List<Payment> payments;
Discount? discount;
PaymentMethod? paymentMethod;
@@ -85,9 +85,9 @@ class Invoice {
}
double getHandlingFee() {
return shipments
.where((sh) => sh.isSelected)
.fold(0, (p, s) => p + (s.handlingFee - s.paidHandlingFee));
return shipments!
.where((sh) => sh!.isSelected)
.fold(0, (p, s) => p + (s!.handlingFee - s.paidHandlingFee));
}
double getTotalBalance(Rate rate) {
@@ -176,7 +176,7 @@ class Invoice {
List _cargoTypes = cargoTypes.map((c) => c.toMap()).toList();
List _customDuties = customDuties.map((c) => c.toMap()).toList();
List _cartons = cartons.map((c) => c.toMap()).toList();
List _shipments = shipments.map((s) => s.toMap()).toList();
List _shipments = shipments!.map((s) => s!.toMap()).toList();
return {
"id": id,
"invoice_date": invoiceDate?.toUtc().toIso8601String(),

View File

@@ -36,7 +36,7 @@ class Package {
DeliveryAddress? deliveryAddress;
//for packages in processing
List<File> photoFiles;
List<File?> photoFiles;
int get amount => rate != null && weight != null ? rate * weight : 0;

View File

@@ -24,20 +24,24 @@ Future<Map?> getClaims({bool refreshIdToken = false}) async {
}
// returns list of url
Future<List<String>> uploadFiles(String path, List<File> files,
Future<List<String>> uploadFiles(String path, List<File?> files,
{String? fileName}) async {
List<Future<String>> fu = [];
for (File f in files) {
for (File? f in files) {
Future<String> u = uploadStorage(path, f);
fu.add(u);
}
return Future.wait(fu);
}
Future<String> uploadStorage(String path, File file, {String? fileName}) async {
Future<String> uploadStorage(String path, File? file,
{String? fileName}) async {
if (fileName == null) {
fileName = Uuid().v4();
}
if (file == null) {
return Future.value('');
}
Reference ref = FirebaseStorage.instance.ref().child('$path/$fileName');
UploadTask uploadTask = ref.putFile(file);
await uploadTask.resume();
@@ -57,10 +61,11 @@ Future<String> uploadStorage(String path, File file, {String? fileName}) async {
// return downloadUrl;
}
Future<void> deleteStorageFromUrls(List<String> urls) async {
Future<void> deleteStorageFromUrls(List<String?> urls) async {
if (urls == null) return;
for (int i = 0; i < urls.length; i++) {
await deleteStorageFromUrl(urls[i]);
if (urls[i] == null) return;
await deleteStorageFromUrl(urls[i]!);
}
}

View File

@@ -39,7 +39,7 @@ class _CargoTypeEditorState extends State<CargoTypeEditor> {
_loadDefalut() {
ShipmentRateModel shipmentRateModel =
Provider.of<ShipmentRateModel>(context, listen: false);
_cargo = shipmentRateModel.rate.defaultCargoType?.clone();
_cargo = shipmentRateModel.rate.defaultCargoType.clone();
}
@override

View File

@@ -171,7 +171,7 @@ class PartSearchDelegate extends SearchDelegate<Carton> {
// }
try {
String barcode = await scanBarcode();
String? barcode = await scanBarcode();
if (barcode != null) {
query = barcode;
showResults(context);

View File

@@ -103,10 +103,10 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
_loadShipments() async {
ShipmentModel shipmentModel =
Provider.of<ShipmentModel>(context, listen: false);
List<Shipment> shipments = await shipmentModel.getShipmentWithHandlingFee(
List<Shipment?>? shipments = await shipmentModel.getShipmentWithHandlingFee(
widget.fcsShipment!.id!, widget.customer!.id!);
shipments.forEach((s) {
s.isSelected = true;
shipments!.forEach((s) {
s!.isSelected = true;
});
setState(() {
_invoice!.shipments = shipments;
@@ -380,8 +380,8 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
if (shipment == null) return;
shipment.isSelected = true;
setState(() {
_invoice!.shipments.remove(shipment);
_invoice!.shipments.add(shipment);
_invoice!.shipments!.remove(shipment);
_invoice!.shipments!.add(shipment);
});
}
@@ -389,8 +389,8 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
if (shipment == null) return;
shipment.isSelected = false;
setState(() {
_invoice!.shipments.remove(shipment);
_invoice!.shipments.add(shipment);
_invoice!.shipments!.remove(shipment);
_invoice!.shipments!.add(shipment);
});
}
@@ -431,7 +431,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
invoice.handlingFee = _invoice!.getHandlingFee();
invoice.cartons = _invoice!.cartons.where((c) => c.isChecked!).toList();
invoice.shipments =
_invoice!.shipments.where((s) => s.isSelected).toList();
_invoice!.shipments!.where((s) => s!.isSelected).toList();
invoice.discount = _invoice!.discount;
invoice.deliveryFee = _invoice!.deliveryFee;

View File

@@ -9,7 +9,7 @@ typedef OnAdd(Shipment shipment);
typedef OnRemove(Shipment shipment);
class InvoiceHandlingFeeList extends StatelessWidget {
final List<Shipment>? shipments;
final List<Shipment?>? shipments;
final OnAdd? onAdd;
final OnRemove? onRemove;
@@ -72,7 +72,7 @@ class InvoiceHandlingFeeList extends StatelessWidget {
onSelectChanged: (value) => Navigator.pop(context, c),
cells: [
MyDataCell(new Text(
c.shipmentNumber!,
c!.shipmentNumber!,
style: textStyle,
)),
MyDataCell(

View File

@@ -39,8 +39,8 @@ class _InvoiceInfoState extends State<InvoiceInfo> {
void initState() {
super.initState();
_invoice = widget.invoice!;
_invoice!.shipments.forEach((s) {
s.isSelected = true;
_invoice!.shipments!.forEach((s) {
s!.isSelected = true;
});
_loadCartons();
}

View File

@@ -70,11 +70,11 @@ class InvoiceTable extends StatelessWidget {
"${c.calWeight.toStringAsFixed(2)} x ${c.calRate.toStringAsFixed(2)}",
amount: "${c.calAmount.toStringAsFixed(2)}"));
});
invoice!.shipments.where((ss) => (ss.isSelected )).forEach((s) {
invoice!.shipments!.where((ss) => (ss!.isSelected )).forEach((s) {
tableRows.add(InvoiceTableRow(
data: s,
invoiceDataType: InvoiceDataType.HandlingFeeType,
desc: "Handling fee\n${s.shipmentNumber}",
desc: "Handling fee\n${s!.shipmentNumber}",
rate: "",
amount: "${s.handlingFee.toStringAsFixed(2)}"));
});

View File

@@ -260,7 +260,7 @@ class PackageModel extends BaseModel {
}
Future<void> createReceiving(
User user, Package package, List<File> files) async {
User user, Package package, List<File?> files) async {
if (user != null) {
package.fcsID = user.fcsID;
}
@@ -288,22 +288,21 @@ class PackageModel extends BaseModel {
}
}
Future<void> updateReceiving(User user, Package package, List<File> files,
List<String> deletedUrls) async {
Future<void> updateReceiving(User user, Package package, List<File?> files,
List<String?> deletedUrls) async {
if (user != null) {
package.fcsID = user.fcsID;
}
if (deletedUrls != null) {
for (String url in deletedUrls) {
for (String? url in deletedUrls) {
package.photoUrls.remove(url);
}
}
List<String> uploadedURL = [];
if (files != null) {
var count = (package.photoUrls?.length ?? 0) +
files.length -
(deletedUrls?.length ?? 0);
var count =
(package.photoUrls.length) + files.length - (deletedUrls.length);
if (count > uploadPhotoLimit)
throw Exception("Exceed number of file upload");
@@ -333,18 +332,17 @@ class PackageModel extends BaseModel {
}
Future<void> updateProcessing(
Package package, List<File> files, List<String> deletedUrls) async {
Package package, List<File?> files, List<String?> deletedUrls) async {
if (deletedUrls != null) {
for (String url in deletedUrls) {
for (String? url in deletedUrls) {
package.photoUrls.remove(url);
}
}
List<String> uploadedURL = [];
if (files != null) {
var count = (package.photoUrls?.length ?? 0) +
files.length -
(deletedUrls?.length ?? 0);
var count =
(package.photoUrls.length) + files.length - (deletedUrls.length);
if (count > uploadPhotoLimit)
throw Exception("Exceed number of file upload");

View File

@@ -164,7 +164,7 @@ class _TrackingIDPageState extends State<TrackingIDPage> {
// }
try {
String barcode = await scanBarcode();
String? barcode = await scanBarcode();
if (barcode != null) {
setState(() {
_transcationIDCtl.text = barcode;

View File

@@ -147,7 +147,7 @@ class PackageSearchDelegate extends SearchDelegate<Package> {
// Barcode bc = barcodes.firstWhere((element) => true);
// String barcode;
// if (bc != null) barcode = bc.rawValue;
String barcode = await scanBarcode();
String? barcode = await scanBarcode();
if (barcode != null) {
query = barcode;
showResults(context);

View File

@@ -80,7 +80,7 @@ class _ProfileState extends State<Profile> {
);
final phonenumberbox = DisplayText(
text: mainModel.user!.phone ?? "",
text: mainModel.user!.phone,
labelTextKey: "profile.phone",
iconData: Icons.phone,
);

View File

@@ -36,7 +36,7 @@ class _CustomEditorState extends State<CustomEditor> {
_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;
}

View File

@@ -86,7 +86,7 @@ class _CustomListState extends State<CustomList> {
custom.rate == null
? ""
: "Shipment rate \$ " +
custom.rate!.toStringAsFixed(2)),
custom.rate.toStringAsFixed(2)),
),
);
}),

View File

@@ -62,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();
});

View File

@@ -212,7 +212,7 @@ class _ReceivingEditorState extends State<ReceivingEditor> {
// }
try {
String barcode = await scanBarcode();
String? barcode = await scanBarcode();
if (barcode != null) {
setState(() {
_trackingIDCtl.text = barcode;

View File

@@ -56,7 +56,7 @@ class _ShipmentAssignState extends State<ShipmentAssign> {
_selectedShipmentType = _shipment!.shipmentType;
_fromTimeEditingController.text = _shipment!.pickupTimeStart!;
_toTimeEditingController.text = _shipment!.pickupTimeEnd!;
_pickupDate.text = dateFormatter.format(_shipment!.pickupDate! ?? now);
_pickupDate.text = dateFormatter.format(_shipment!.pickupDate ?? now);
_handlingFee.text = _shipment!.handlingFee != null
? _shipment!.handlingFee.toString()
: "0";

View File

@@ -37,7 +37,7 @@ class _ShipmentConfirmState extends State<ShipmentConfirm> {
super.initState();
_shipment = widget.shipment;
_handlingFee.text = _shipment!.handlingFee?.toString() ?? "0";
_handlingFee.text = _shipment!.handlingFee.toString();
}
@override

View File

@@ -223,7 +223,7 @@ class _ShipmentInfoState extends State<ShipmentInfo> {
iconData: MaterialCommunityIcons.worker);
var handlingFeeBox = DisplayText(
labelTextKey: "shipment.handling.fee",
text: (_shipment!.handlingFee ?? 0).toString(),
text: (_shipment!.handlingFee).toString(),
iconData: FontAwesome.truck);
final assignCompleteBtn = LocalButton(

View File

@@ -80,7 +80,7 @@ class MultiImgController {
List<File?> get getUpdatedFile {
List<File?> _addfiles = getAddedFile;
this.imageFiles!.addAll(_addfiles);
this.imageFiles.addAll(_addfiles);
return this.imageFiles;
}