null safety
This commit is contained in:
@@ -31,15 +31,15 @@ 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/flutter_icons.dart';
|
||||
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class InvoiceEditor extends StatefulWidget {
|
||||
final Invoice invoice;
|
||||
final User customer;
|
||||
final FcsShipment fcsShipment;
|
||||
final Invoice? invoice;
|
||||
final User? customer;
|
||||
final FcsShipment? fcsShipment;
|
||||
InvoiceEditor({this.invoice, this.customer, this.fcsShipment});
|
||||
|
||||
@override
|
||||
@@ -49,10 +49,10 @@ class InvoiceEditor extends StatefulWidget {
|
||||
class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
|
||||
Invoice _invoice;
|
||||
Invoice? _invoice;
|
||||
bool _isLoading = false;
|
||||
bool _isNew;
|
||||
User _user;
|
||||
bool _isNew = false;
|
||||
User? _user;
|
||||
|
||||
bool _showCartons = false;
|
||||
@override
|
||||
@@ -91,12 +91,12 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
_loadCartons() async {
|
||||
CartonModel cartonModel = Provider.of<CartonModel>(context, listen: false);
|
||||
List<Carton> cartons = await cartonModel.getCartonsForInvoice(
|
||||
widget.fcsShipment.id, widget.customer.id);
|
||||
widget.fcsShipment!.id, widget.customer!.id);
|
||||
cartons.forEach((c) {
|
||||
c.isChecked = true;
|
||||
});
|
||||
setState(() {
|
||||
_invoice.cartons = cartons;
|
||||
_invoice!.cartons = cartons;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -104,12 +104,12 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
ShipmentModel shipmentModel =
|
||||
Provider.of<ShipmentModel>(context, listen: false);
|
||||
List<Shipment> shipments = await shipmentModel.getShipmentWithHandlingFee(
|
||||
widget.fcsShipment.id, widget.customer.id);
|
||||
widget.fcsShipment!.id, widget.customer!.id);
|
||||
shipments.forEach((s) {
|
||||
s.isSelected = true;
|
||||
});
|
||||
setState(() {
|
||||
_invoice.shipments = shipments;
|
||||
_invoice!.shipments = shipments;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -117,10 +117,10 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
_loadDiscount() async {
|
||||
DiscountModel discountModel =
|
||||
Provider.of<DiscountModel>(context, listen: false);
|
||||
discounts = await discountModel.getDiscount(widget.customer.id);
|
||||
discounts = await discountModel.getDiscount(widget.customer!.id);
|
||||
if (discounts != null && discounts.length > 0) {
|
||||
setState(() {
|
||||
_invoice.discount = discounts.first;
|
||||
_invoice!.discount = discounts.first;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -146,7 +146,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
iconData: Icons.av_timer,
|
||||
labelTextKey: 'invoice.status');
|
||||
final cartonTable = InvoiceCartonTable(
|
||||
cartons: _invoice.cartons,
|
||||
cartons: _invoice!.cartons,
|
||||
rate: rate,
|
||||
onSelect: (c, checked) {
|
||||
setState(() {
|
||||
@@ -157,30 +157,30 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
final paymentTypesBox = LocalDropdown<PaymentMethod>(
|
||||
callback: (v) {
|
||||
setState(() {
|
||||
_invoice.paymentMethod = v;
|
||||
_invoice!.paymentMethod = v;
|
||||
});
|
||||
},
|
||||
labelKey: "invoice.payment_method",
|
||||
iconData: FontAwesome.money,
|
||||
display: (u) => u.name,
|
||||
selectedValue: _invoice.paymentMethod,
|
||||
selectedValue: _invoice!.paymentMethod,
|
||||
values: paymentMethodModel.paymentMethods,
|
||||
);
|
||||
final invoiceTableBox = InvoiceTable(
|
||||
invoice: _invoice,
|
||||
invoice: _invoice!,
|
||||
rate: rate,
|
||||
deliveryFeeSelected: (selected) {
|
||||
setState(() {
|
||||
if (selected) {
|
||||
_invoice.deliveryFee = rate.deliveryFee;
|
||||
_invoice!.deliveryFee = rate.deliveryFee;
|
||||
} else {
|
||||
_invoice.deliveryFee = 0;
|
||||
_invoice!.deliveryFee = 0;
|
||||
}
|
||||
});
|
||||
},
|
||||
discountSelected: (discount) {
|
||||
setState(() {
|
||||
_invoice.discount = discount;
|
||||
_invoice!.discount = discount;
|
||||
});
|
||||
},
|
||||
onRemove: (i) {
|
||||
@@ -189,12 +189,12 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
}
|
||||
if (i.invoiceDataType == InvoiceDataType.DiscountDataType) {
|
||||
setState(() {
|
||||
_invoice.discount = null;
|
||||
_invoice!.discount = new Discount();
|
||||
});
|
||||
}
|
||||
if (i.invoiceDataType == InvoiceDataType.DeliveryFeeType) {
|
||||
setState(() {
|
||||
_invoice.deliveryFee = 0;
|
||||
_invoice!.deliveryFee = 0;
|
||||
});
|
||||
}
|
||||
if (i.invoiceDataType == InvoiceDataType.HandlingFeeType) {
|
||||
@@ -254,7 +254,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
Shipment shipment = await Navigator.of(context).push(
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
InvoiceHandlingFeeList(shipments: _invoice.shipments)));
|
||||
InvoiceHandlingFeeList(shipments: _invoice!.shipments)));
|
||||
_addShipment(shipment);
|
||||
} else if (p.id == 3) {
|
||||
Discount discount =
|
||||
@@ -264,12 +264,12 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
)));
|
||||
if (discount != null) {
|
||||
setState(() {
|
||||
_invoice.discount = discount;
|
||||
_invoice!.discount = discount;
|
||||
});
|
||||
}
|
||||
} else if (p.id == 4) {
|
||||
setState(() {
|
||||
_invoice.deliveryFee = rate.deliveryFee;
|
||||
_invoice!.deliveryFee = rate.deliveryFee;
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -281,7 +281,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(dateFormatter.format(_invoice.invoiceDate)),
|
||||
Text(dateFormatter.format(_invoice!.invoiceDate)),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
@@ -371,8 +371,8 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
_addCustom(CustomDuty customDuty) {
|
||||
if (customDuty == null) return;
|
||||
setState(() {
|
||||
_invoice.customDuties.remove(customDuty);
|
||||
_invoice.customDuties.add(customDuty);
|
||||
_invoice!.customDuties.remove(customDuty);
|
||||
_invoice!.customDuties.add(customDuty);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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,30 +389,30 @@ 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);
|
||||
});
|
||||
}
|
||||
|
||||
_removeCustom(CustomDuty customDuty) {
|
||||
setState(() {
|
||||
_invoice.customDuties.remove(customDuty);
|
||||
_invoice!.customDuties.remove(customDuty);
|
||||
});
|
||||
}
|
||||
|
||||
_save() async {
|
||||
var rateModel = Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
double amount = _invoice.getNetAmount(rateModel.rate);
|
||||
if (_invoice.paymentMethod == null) {
|
||||
double amount = _invoice!.getNetAmount(rateModel.rate);
|
||||
if (_invoice!.paymentMethod == null) {
|
||||
showMsgDialog(context, "Error", "Payment method required");
|
||||
return;
|
||||
}
|
||||
List<CargoType> cargoTypes = _invoice.getCargoTypes(rateModel.rate);
|
||||
List<CargoType> cargoTypes = _invoice!.getCargoTypes(rateModel.rate);
|
||||
if (cargoTypes == null || cargoTypes.length == 0) {
|
||||
showMsgDialog(context, "Error", "Expected at least one cargo type");
|
||||
return;
|
||||
}
|
||||
if ((amount ?? 0) <= 0) {
|
||||
if ((amount ) <= 0) {
|
||||
showMsgDialog(context, "Error", "Expected positive amount");
|
||||
return;
|
||||
}
|
||||
@@ -428,18 +428,18 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
Invoice invoice = Invoice();
|
||||
invoice.cargoTypes = cargoTypes;
|
||||
invoice.amount = amount;
|
||||
invoice.handlingFee = _invoice.getHandlingFee();
|
||||
invoice.cartons = _invoice.cartons.where((c) => c.isChecked).toList();
|
||||
invoice.handlingFee = _invoice!.getHandlingFee();
|
||||
invoice.cartons = _invoice!.cartons.where((c) => c.isChecked).toList();
|
||||
invoice.shipments =
|
||||
_invoice.shipments.where((s) => s.isSelected).toList();
|
||||
invoice.discount = _invoice.discount;
|
||||
invoice.deliveryFee = _invoice.deliveryFee;
|
||||
_invoice!.shipments.where((s) => s.isSelected).toList();
|
||||
invoice.discount = _invoice!.discount;
|
||||
invoice.deliveryFee = _invoice!.deliveryFee;
|
||||
|
||||
invoice.userID = widget.customer.id;
|
||||
invoice.fcsShipmentID = widget.fcsShipment.id;
|
||||
invoice.invoiceDate = _invoice.invoiceDate;
|
||||
invoice.paymentMethod = _invoice.paymentMethod;
|
||||
invoice.customDuties = _invoice.customDuties;
|
||||
invoice.userID = widget.customer!.id;
|
||||
invoice.fcsShipmentID = widget.fcsShipment!.id;
|
||||
invoice.invoiceDate = _invoice!.invoiceDate;
|
||||
invoice.paymentMethod = _invoice!.paymentMethod;
|
||||
invoice.customDuties = _invoice!.customDuties;
|
||||
|
||||
await invoiceModel.createInvoice(invoice);
|
||||
Navigator.pop(context, true);
|
||||
|
||||
Reference in New Issue
Block a user