null safety

This commit is contained in:
phyothandar
2021-09-10 12:00:08 +06:30
parent a144c945b6
commit 5e672937b5
67 changed files with 901 additions and 896 deletions

View File

@@ -9,11 +9,11 @@ import 'package:flutter/material.dart';
typedef OnSelect = Function(Carton carton, bool checked);
class InvoiceCartonTable extends StatelessWidget {
final List<Carton> cartons;
final OnSelect onSelect;
final Rate rate;
final List<Carton>? cartons;
final OnSelect? onSelect;
final Rate? rate;
const InvoiceCartonTable({Key key, this.cartons, this.onSelect, this.rate})
const InvoiceCartonTable({Key? key, this.cartons, this.onSelect, this.rate})
: super(key: key);
@override
@@ -36,20 +36,20 @@ class InvoiceCartonTable extends StatelessWidget {
final rows = cartons == null
? [Container()]
: cartons.asMap().entries.map((p) {
: cartons!.asMap().entries.map((p) {
return Container(
color: p.value.isChecked
? Colors.grey.withOpacity(0.2)
: Colors.grey[50].withOpacity(0.2),
: Colors.grey.shade50.withOpacity(0.2),
child: Container(
padding: EdgeInsets.only(
left: 0.0, right: 10.0, top: 3.0, bottom: 3.0),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: p.key == cartons.length - 1
color: p.key == cartons!.length - 1
? Colors.white
: Colors.grey[350],
: Colors.grey.shade300,
width: 1),
),
),
@@ -64,8 +64,8 @@ class InvoiceCartonTable extends StatelessWidget {
: Checkbox(
value: p.value.isChecked,
activeColor: primaryColor,
onChanged: (bool check) {
if (onSelect != null) onSelect(p.value, check);
onChanged: (bool? check) {
if (onSelect != null) onSelect!(p.value, check!);
}),
Expanded(
child: Column(
@@ -82,15 +82,15 @@ class InvoiceCartonTable extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
new Text(
"${p.value?.length ?? ""} x ${p.value?.width ?? ""} x ${p.value?.height ?? ""}",
"${p.value.length} x ${p.value.width} x ${p.value.height}",
style: textStyle,
),
new Text(
"${p.value?.getShipmentWeight(rate.volumetricRatio)?.toStringAsFixed(2) ?? "0"} lb",
"${p.value.getShipmentWeight(rate!.volumetricRatio).toStringAsFixed(2)} lb",
style: textStyle,
),
new Text(
"${p.value?.actualWeight?.toStringAsFixed(2) ?? "0"} lb (Actual)",
"${p.value.actualWeight.toStringAsFixed(2)} lb (Actual)",
style: textStyle,
),
],

View File

@@ -6,10 +6,10 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class InvoiceDiscountList extends StatelessWidget {
final List<Discount> discounts;
final List<Discount>? discounts;
const InvoiceDiscountList({
Key key,
Key? key,
this.discounts,
}) : super(key: key);
@@ -63,19 +63,19 @@ class InvoiceDiscountList extends StatelessWidget {
if (discounts == null) {
return [];
}
var rows = discounts.map((c) {
var rows = discounts!.map((c) {
return MyDataRow(
onSelectChanged: (value) => Navigator.pop(context, c),
cells: [
MyDataCell(new Text(
c.code ?? "",
c.code,
style: textStyle,
)),
MyDataCell(
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(c.amount?.toStringAsFixed(2) ?? "0", style: textStyle),
Text(c.amount.toStringAsFixed(2), style: textStyle),
],
),
),

View File

@@ -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);

View File

@@ -9,12 +9,12 @@ typedef OnAdd(Shipment shipment);
typedef OnRemove(Shipment shipment);
class InvoiceHandlingFeeList extends StatelessWidget {
final List<Shipment> shipments;
final OnAdd onAdd;
final OnRemove onRemove;
final List<Shipment>? shipments;
final OnAdd? onAdd;
final OnRemove? onRemove;
const InvoiceHandlingFeeList(
{Key key, this.shipments, this.onAdd, this.onRemove})
{Key? key, this.shipments, this.onAdd, this.onRemove})
: super(key: key);
@override
@@ -67,20 +67,19 @@ class InvoiceHandlingFeeList extends StatelessWidget {
if (shipments == null) {
return [];
}
var rows = shipments.map((c) {
var rows = shipments!.map((c) {
return MyDataRow(
onSelectChanged: (value) => Navigator.pop(context, c),
cells: [
MyDataCell(new Text(
c.shipmentNumber ?? "",
c.shipmentNumber,
style: textStyle,
)),
MyDataCell(
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(c.handlingFee?.toStringAsFixed(2) ?? "0",
style: textStyle),
Text(c.handlingFee.toStringAsFixed(2), style: textStyle),
onRemove == null
? SizedBox(
width: 50,
@@ -91,7 +90,7 @@ class InvoiceHandlingFeeList extends StatelessWidget {
color: primaryColor,
),
onPressed: () {
if (onRemove != null) onRemove(c);
if (onRemove != null) onRemove!(c);
})
],
),