null safety
This commit is contained in:
@@ -20,8 +20,8 @@ import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class InvoiceInfo extends StatefulWidget {
|
||||
final Invoice invoice;
|
||||
final bool forCustomer;
|
||||
final Invoice? invoice;
|
||||
final bool? forCustomer;
|
||||
InvoiceInfo({this.invoice, this.forCustomer});
|
||||
|
||||
@override
|
||||
@@ -31,15 +31,15 @@ class InvoiceInfo extends StatefulWidget {
|
||||
class _InvoiceInfoState extends State<InvoiceInfo> {
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
|
||||
Invoice _invoice;
|
||||
Invoice? _invoice;
|
||||
bool _isLoading = false;
|
||||
|
||||
bool _showCartons = false;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_invoice = widget.invoice;
|
||||
_invoice.shipments?.forEach((s) {
|
||||
_invoice = widget.invoice!;
|
||||
_invoice!.shipments.forEach((s) {
|
||||
s.isSelected = true;
|
||||
});
|
||||
_loadCartons();
|
||||
@@ -54,7 +54,7 @@ class _InvoiceInfoState extends State<InvoiceInfo> {
|
||||
cartons.add(_carton);
|
||||
}
|
||||
setState(() {
|
||||
_invoice.cartons = cartons;
|
||||
_invoice!.cartons = cartons;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -65,31 +65,31 @@ class _InvoiceInfoState extends State<InvoiceInfo> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool isCanceled = _invoice.status == invoice_cancel_status;
|
||||
bool isPaid = _invoice.status == invoice_paid_status;
|
||||
bool isCanceled = _invoice!.status == invoice_cancel_status;
|
||||
bool isPaid = _invoice!.status == invoice_paid_status;
|
||||
var rateModel = Provider.of<ShipmentRateModel>(context);
|
||||
var rate = rateModel.rate;
|
||||
|
||||
final cartonTable = InvoiceCartonTable(
|
||||
cartons: _invoice.cartons,
|
||||
cartons: _invoice!.cartons,
|
||||
rate: rate,
|
||||
);
|
||||
|
||||
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;
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -118,7 +118,7 @@ class _InvoiceInfoState extends State<InvoiceInfo> {
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(dateFormatter.format(_invoice.invoiceDate)),
|
||||
Text(dateFormatter.format(_invoice!.invoiceDate)),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
@@ -140,7 +140,7 @@ class _InvoiceInfoState extends State<InvoiceInfo> {
|
||||
);
|
||||
final paymentMethodBox = DisplayText(
|
||||
labelTextKey: "invoice.payment_method",
|
||||
text: _invoice.paymentMethod.name,
|
||||
text: _invoice!.paymentMethod.name,
|
||||
);
|
||||
|
||||
final cancelBtn = LocalButton(
|
||||
@@ -166,7 +166,7 @@ class _InvoiceInfoState extends State<InvoiceInfo> {
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
getInvoiceStatus(context, _invoice),
|
||||
getInvoiceStatus(context, _invoice!),
|
||||
headerBox,
|
||||
_showCartons ? cartonTable : Container(),
|
||||
_showCartons
|
||||
@@ -183,7 +183,7 @@ class _InvoiceInfoState extends State<InvoiceInfo> {
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
isCanceled || isPaid || widget.forCustomer
|
||||
isCanceled || isPaid || widget.forCustomer!
|
||||
? Container()
|
||||
: cancelBtn,
|
||||
],
|
||||
@@ -206,7 +206,7 @@ class _InvoiceInfoState extends State<InvoiceInfo> {
|
||||
InvoiceModel invoiceModel =
|
||||
Provider.of<InvoiceModel>(context, listen: false);
|
||||
|
||||
await invoiceModel.cancelInvoice(_invoice);
|
||||
await invoiceModel.cancelInvoice(_invoice!);
|
||||
Navigator.pop(context, true);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
|
||||
Reference in New Issue
Block a user