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

@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class BoxAddition extends StatefulWidget {
final Carton box;
final Carton? box;
BoxAddition({this.box});
@override
@@ -23,7 +23,7 @@ class _BoxAdditionState extends State<BoxAddition> {
void initState() {
super.initState();
if (widget.box != null) {
_box = widget.box;
_box = widget.box!;
}
}
@@ -54,7 +54,7 @@ class _BoxAdditionState extends State<BoxAddition> {
child: Padding(
padding: const EdgeInsets.all(10.0),
child: ListView(children: <Widget>[
DropdownButtonFormField(
DropdownButtonFormField<Object>(
decoration: InputDecoration(
fillColor: Colors.white,
labelText: 'Box Number',

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);
})
],
),

View File

@@ -11,9 +11,9 @@ import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
class InvoiceCustomerList extends StatefulWidget {
final FcsShipment fcsShipment;
final FcsShipment? fcsShipment;
const InvoiceCustomerList({Key key, this.fcsShipment}) : super(key: key);
const InvoiceCustomerList({Key? key, this.fcsShipment}) : super(key: key);
@override
_InvoiceCustomerListState createState() => _InvoiceCustomerListState();
@@ -33,7 +33,7 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
_load() async {
CustomerModel customerModel =
Provider.of<CustomerModel>(context, listen: false);
var users = await customerModel.getInvoiceUsers(widget.fcsShipment.id);
var users = await customerModel.getInvoiceUsers(widget.fcsShipment!.id);
setState(() {
_users = users;
});
@@ -88,7 +88,7 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
customer: customer,
fcsShipment: widget.fcsShipment,
)));
if (created ?? false) {
if (created) {
_load();
}
},

View File

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

View File

@@ -12,9 +12,9 @@ import 'package:provider/provider.dart';
import 'invoice_list_row.dart';
class InvoiceList extends StatefulWidget {
final bool forCustomer;
final bool? forCustomer;
const InvoiceList({Key key, this.forCustomer}) : super(key: key);
const InvoiceList({Key? key, this.forCustomer}) : super(key: key);
@override
_InvoiceListState createState() => _InvoiceListState();
}
@@ -29,13 +29,13 @@ class _InvoiceListState extends State<InvoiceList> {
_controller.addListener(() async {
if (_controller.position.pixels == _controller.position.maxScrollExtent) {
Provider.of<InvoiceModel>(context, listen: false)
.loadMore(isCustomer: widget.forCustomer);
.loadMore(isCustomer: widget.forCustomer!);
}
});
InvoiceModel invoiceModel =
Provider.of<InvoiceModel>(context, listen: false);
invoiceModel.initData(widget.forCustomer, true, false);
invoiceModel.initData(widget.forCustomer!, true, false);
}
@override
@@ -66,13 +66,13 @@ class _InvoiceListState extends State<InvoiceList> {
invoiceModel.selectedIndex = p.id;
if (p.id == 2) {
Provider.of<InvoiceModel>(context, listen: false)
.initData(widget.forCustomer, false, true);
.initData(widget.forCustomer!, false, true);
} else if (p.id == 3) {
Provider.of<InvoiceModel>(context, listen: false)
.initData(widget.forCustomer, true, false);
.initData(widget.forCustomer!, true, false);
} else {
Provider.of<InvoiceModel>(context, listen: false)
.initData(widget.forCustomer, true, false);
.initData(widget.forCustomer!, true, false);
}
}),
);
@@ -93,7 +93,7 @@ class _InvoiceListState extends State<InvoiceList> {
color: Colors.white, fontSize: 20),
actions: <Widget>[popupMenu],
),
floatingActionButton: widget.forCustomer
floatingActionButton: widget.forCustomer!
? null
: FloatingActionButton.extended(
onPressed: () {

View File

@@ -12,9 +12,9 @@ import '../widgets/pdf_screen.dart';
class InvoiceListRow extends StatelessWidget {
final dateFormatter = new DateFormat('dd MMM yyyy');
final Invoice invoice;
final bool forCustomer;
InvoiceListRow({Key key, this.invoice, this.forCustomer}) : super(key: key);
final Invoice? invoice;
final bool? forCustomer;
InvoiceListRow({Key? key, this.invoice, this.forCustomer}) : super(key: key);
@override
Widget build(BuildContext context) {
@@ -22,8 +22,8 @@ class InvoiceListRow extends StatelessWidget {
onTap: () {
Navigator.of(context).push(CupertinoPageRoute(
builder: (context) => PDFScreen(
title: invoice.invoiceNumber,
url: invoice.invoiceURL,
title: invoice!.invoiceNumber,
url: invoice!.invoiceURL,
)));
},
child: Row(
@@ -48,17 +48,17 @@ class InvoiceListRow extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(
invoice.invoiceNumber ?? "",
invoice!.invoiceNumber ?? "",
style: new TextStyle(
fontSize: 15.0, color: Colors.black),
),
new Text(
invoice.status ?? "",
invoice!.status ?? "",
style: new TextStyle(
fontSize: 13.0, color: primaryColor),
),
new Text(
dateFormatter.format(invoice.invoiceDate),
dateFormatter.format(invoice!.invoiceDate),
style: new TextStyle(
fontSize: 15.0, color: Colors.grey),
)
@@ -70,7 +70,7 @@ class InvoiceListRow extends StatelessWidget {
),
),
),
invoice.status == invoice_issued_status
invoice!.status == invoice_issued_status
? Padding(
padding: const EdgeInsets.only(left: 10.0),
child: InkWell(

View File

@@ -2,7 +2,7 @@ import 'package:fcs/domain/entities/fcs_shipment.dart';
import 'package:fcs/helpers/theme.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:intl/intl.dart';
import '../main/util.dart';
@@ -11,8 +11,8 @@ import 'invoice_customer_list.dart';
typedef OnSelect(FcsShipment fcsShipment);
class InvoiceShipmentListRow extends StatefulWidget {
final OnSelect onSelect;
final FcsShipment fcsShipment;
final OnSelect? onSelect;
final FcsShipment? fcsShipment;
const InvoiceShipmentListRow({this.fcsShipment, this.onSelect});
@override
@@ -28,7 +28,7 @@ class _InvoiceShipmentListRowState extends State<InvoiceShipmentListRow> {
void initState() {
super.initState();
if (widget.fcsShipment != null) {
_fcsShipment = widget.fcsShipment;
_fcsShipment = widget.fcsShipment!;
}
}
@@ -38,7 +38,7 @@ class _InvoiceShipmentListRowState extends State<InvoiceShipmentListRow> {
padding: EdgeInsets.only(left: 15, right: 15),
child: InkWell(
onTap: () {
if (widget.onSelect != null) widget.onSelect(widget.fcsShipment);
if (widget.onSelect != null) widget.onSelect!(widget.fcsShipment!);
},
child: Row(
children: <Widget>[

View File

@@ -23,11 +23,11 @@ enum InvoiceDataType {
class InvoiceTableRow {
final dynamic data;
final String id;
final InvoiceDataType invoiceDataType;
final String desc;
final String rate;
final String amount;
final String? id;
final InvoiceDataType? invoiceDataType;
final String? desc;
final String? rate;
final String? amount;
InvoiceTableRow(
{this.id,
@@ -39,14 +39,14 @@ class InvoiceTableRow {
}
class InvoiceTable extends StatelessWidget {
final Invoice invoice;
final Rate rate;
final OnDiscountSelected discountSelected;
final OnDeliveryFeeSelected deliveryFeeSelected;
final OnRemove onRemove;
final Invoice? invoice;
final Rate? rate;
final OnDiscountSelected? discountSelected;
final OnDeliveryFeeSelected? deliveryFeeSelected;
final OnRemove? onRemove;
const InvoiceTable(
{Key key,
{Key? key,
this.invoice,
this.discountSelected,
this.deliveryFeeSelected,
@@ -61,16 +61,16 @@ class InvoiceTable extends StatelessWidget {
List<InvoiceTableRow> getTableRows() {
List<InvoiceTableRow> tableRows = [];
// add cargo types
List<CargoType> _cargoTypes = invoice.getCargoTypes(rate) ?? [];
List<CargoType> _cargoTypes = invoice!.getCargoTypes(rate!) ?? [];
_cargoTypes.forEach((c) {
tableRows.add(InvoiceTableRow(
invoiceDataType: InvoiceDataType.CargoDataType,
desc: c.name,
rate:
"${c.calWeight.toStringAsFixed(2)} x ${c.calRate.toStringAsFixed(2)}",
"${c.calWeight!.toStringAsFixed(2)} x ${c.calRate!.toStringAsFixed(2)}",
amount: "${c.calAmount.toStringAsFixed(2)}"));
});
invoice.shipments.where((ss) => (ss.isSelected ?? false)).forEach((s) {
invoice!.shipments.where((ss) => (ss.isSelected ?? false)).forEach((s) {
tableRows.add(InvoiceTableRow(
data: s,
invoiceDataType: InvoiceDataType.HandlingFeeType,
@@ -79,7 +79,7 @@ class InvoiceTable extends StatelessWidget {
amount: "${s.handlingFee.toStringAsFixed(2)}"));
});
// // add custom fee
invoice.customDuties.forEach((c) {
invoice!.customDuties.forEach((c) {
tableRows.add(InvoiceTableRow(
data: c,
invoiceDataType: InvoiceDataType.CustomFeeDataType,
@@ -89,18 +89,18 @@ class InvoiceTable extends StatelessWidget {
});
// // add delivery fee
tableRows.add(InvoiceTableRow(
data: invoice.deliveryFee == null || invoice.deliveryFee == 0
data: invoice!.deliveryFee == null || invoice!.deliveryFee == 0
? null
: invoice.deliveryFee,
: invoice!.deliveryFee,
invoiceDataType: InvoiceDataType.DeliveryFeeType,
desc: "Delivery fee",
rate: "",
amount: "${invoice?.deliveryFee?.toStringAsFixed(2) ?? '0'}"));
// // add discounts
if (invoice.discount != null) {
if (invoice!.discount != null) {
tableRows.add(InvoiceTableRow(
data: invoice.discount,
data: invoice!.discount,
invoiceDataType: InvoiceDataType.DiscountDataType,
desc: "Discount\n${invoice?.discount?.code ?? ""}",
rate: "",
@@ -132,7 +132,7 @@ class InvoiceTable extends StatelessWidget {
r.data == null || onRemove == null
? Container()
: InkWell(
onTap: () => onRemove(r),
onTap: () => onRemove!(r),
child: Icon(
Icons.remove_circle,
color: Colors.black45,
@@ -217,7 +217,7 @@ class InvoiceTable extends StatelessWidget {
),
SizedBox(width: 20),
Text(
'\$ ${invoice.getNetAmount(rate).toStringAsFixed(2)}',
'\$ ${invoice!.getNetAmount(rate!).toStringAsFixed(2)}',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
)

View File

@@ -20,8 +20,8 @@ import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
class PaymentPage extends StatefulWidget {
final Invoice invoice;
final bool forCustomer;
final Invoice? invoice;
final bool? forCustomer;
PaymentPage({this.invoice, this.forCustomer});
@override
@@ -35,15 +35,15 @@ class _PaymentPageState extends State<PaymentPage> {
Invoice _invoice = new Invoice();
bool _isLoading = false;
bool isNew;
File _file;
bool _hasBalance;
bool isNew = false;
File? _file;
bool _hasBalance = false;
@override
void initState() {
super.initState();
_invoice = widget.invoice;
_hasBalance = widget.invoice.balance > 0;
_invoice = widget.invoice!;
_hasBalance = widget.invoice!.balance > 0;
_loadInvoice();
}
@@ -129,7 +129,7 @@ class _PaymentPageState extends State<PaymentPage> {
getCustomFeeRows(BuildContext context) {
List<Widget> dataRow = [];
dataRow = _invoice?.payments?.map((p) {
dataRow = _invoice.payments.map((p) {
return Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey))),
@@ -165,7 +165,7 @@ class _PaymentPageState extends State<PaymentPage> {
child: Column(
children: [Text('\$ ${p.amount}'), Text('${p.status}')],
))),
widget.forCustomer
widget.forCustomer!
? Container()
: Expanded(
flex: 1,
@@ -197,8 +197,7 @@ class _PaymentPageState extends State<PaymentPage> {
],
),
);
})?.toList() ??
[];
}).toList() ;
dataRow.insert(
0,
@@ -217,7 +216,7 @@ class _PaymentPageState extends State<PaymentPage> {
child: Text('Amount',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey))),
widget.forCustomer
widget.forCustomer!
? Container()
: Expanded(
flex: 1,
@@ -250,11 +249,11 @@ class _PaymentPageState extends State<PaymentPage> {
flex: 1,
child: Center(
child: Text(
'\$ ${widget.invoice.balance.toStringAsFixed(2)}',
'\$ ${widget.invoice!.balance.toStringAsFixed(2)}',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 16.0)))),
widget.forCustomer
widget.forCustomer!
? Container()
: Expanded(
flex: 1,
@@ -279,7 +278,7 @@ class _PaymentPageState extends State<PaymentPage> {
}
_updatePayment(Payment payment) async {
payment.invoiceID = widget.invoice.id;
payment.invoiceID = widget.invoice!.id;
setState(() {
_isLoading = true;
});
@@ -314,7 +313,7 @@ class _PaymentPageState extends State<PaymentPage> {
try {
InvoiceModel invoiceModel =
Provider.of<InvoiceModel>(context, listen: false);
await invoiceModel.pay(payment, _file);
await invoiceModel.pay(payment, _file!);
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -20,7 +20,7 @@ import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
class PaymentPageEdit extends StatefulWidget {
final Receipt receipt;
final Receipt? receipt;
PaymentPageEdit({this.receipt});
@override
@@ -33,14 +33,14 @@ class _PaymentPageEditState extends State<PaymentPageEdit> {
Receipt _receipt = new Receipt();
bool _isLoading = false;
File _file;
File? _file;
bool isNew;
bool isNew = false;
@override
void initState() {
if (widget.receipt != null) {
_receipt = widget.receipt;
_receipt = widget.receipt!;
}
super.initState();
}
@@ -185,11 +185,11 @@ class _PaymentPageEditState extends State<PaymentPageEdit> {
return initialImage();
} else {
Widget _widget;
if (widget.receipt.fileUrl == null) {
if (widget.receipt!.fileUrl == null) {
_widget = initialImage();
} else {
_widget = InkWell(
child: Image.asset(widget.receipt.fileUrl, fit: BoxFit.cover),
child: Image.asset(widget.receipt!.fileUrl, fit: BoxFit.cover),
onTap: () {},
);
}
@@ -209,13 +209,13 @@ class _PaymentPageEditState extends State<PaymentPageEdit> {
Widget enableUpload(BuildContext context) {
return InkWell(
child: Image.file(_file, fit: BoxFit.cover),
child: Image.file(_file!, fit: BoxFit.cover),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
ShowImage(imageFile: _file, url: null, fileName: 'image')));
ShowImage(imageFile: _file!, url: '', fileName: 'image')));
},
);
}