null safety
This commit is contained in:
@@ -45,7 +45,7 @@ class _BoxAdditionState extends State<BoxAddition> {
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("box.edit.title")),
|
||||
title: Text(AppTranslations.of(context)!.text("box.edit.title")),
|
||||
),
|
||||
body: Card(
|
||||
child: Column(
|
||||
|
||||
@@ -38,7 +38,7 @@ class InvoiceCartonTable extends StatelessWidget {
|
||||
? [Container()]
|
||||
: cartons!.asMap().entries.map((p) {
|
||||
return Container(
|
||||
color: p.value.isChecked
|
||||
color: p.value.isChecked!
|
||||
? Colors.grey.withOpacity(0.2)
|
||||
: Colors.grey.shade50.withOpacity(0.2),
|
||||
child: Container(
|
||||
@@ -56,7 +56,7 @@ class InvoiceCartonTable extends StatelessWidget {
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
onSelect == null
|
||||
? p.value.isChecked
|
||||
? p.value.isChecked!
|
||||
? SizedBox(
|
||||
child: Icon(Icons.check, color: primaryColor),
|
||||
width: 30)
|
||||
@@ -72,7 +72,7 @@ class InvoiceCartonTable extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
p.value.cartonNumber,
|
||||
p.value.cartonNumber!,
|
||||
style: textStyle,
|
||||
),
|
||||
],
|
||||
|
||||
@@ -68,7 +68,7 @@ class InvoiceDiscountList extends StatelessWidget {
|
||||
onSelectChanged: (value) => Navigator.pop(context, c),
|
||||
cells: [
|
||||
MyDataCell(new Text(
|
||||
c.code,
|
||||
c.code!,
|
||||
style: textStyle,
|
||||
)),
|
||||
MyDataCell(
|
||||
|
||||
@@ -91,7 +91,7 @@ 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;
|
||||
});
|
||||
@@ -104,7 +104,7 @@ 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;
|
||||
});
|
||||
@@ -117,7 +117,7 @@ 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;
|
||||
@@ -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,
|
||||
),
|
||||
@@ -429,7 +429,7 @@ class _InvoiceEditorState extends State<InvoiceEditor> {
|
||||
invoice.cargoTypes = cargoTypes;
|
||||
invoice.amount = amount;
|
||||
invoice.handlingFee = _invoice!.getHandlingFee();
|
||||
invoice.cartons = _invoice!.cartons.where((c) => c.isChecked).toList();
|
||||
invoice.cartons = _invoice!.cartons.where((c) => c.isChecked!).toList();
|
||||
invoice.shipments =
|
||||
_invoice!.shipments.where((s) => s.isSelected).toList();
|
||||
invoice.discount = _invoice!.discount;
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
@@ -125,7 +125,7 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2.0),
|
||||
child: new Text(
|
||||
customer.name,
|
||||
customer.name!,
|
||||
style: new TextStyle(
|
||||
fontSize: 20.0, color: primaryColor),
|
||||
),
|
||||
@@ -133,7 +133,7 @@ class _InvoiceCustomerListState extends State<InvoiceCustomerList> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 2.0),
|
||||
child: new Text(
|
||||
customer.phoneNumber,
|
||||
customer.phoneNumber!,
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -58,7 +58,7 @@ class InvoiceListRow extends StatelessWidget {
|
||||
fontSize: 13.0, color: primaryColor),
|
||||
),
|
||||
new Text(
|
||||
dateFormatter.format(invoice!.invoiceDate),
|
||||
dateFormatter.format(invoice!.invoiceDate!),
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.grey),
|
||||
)
|
||||
|
||||
@@ -64,7 +64,7 @@ class _InvoiceShipmentListRowState extends State<InvoiceShipmentListRow> {
|
||||
child: new Text(
|
||||
_fcsShipment.shipmentNumber == null
|
||||
? ''
|
||||
: _fcsShipment.shipmentNumber,
|
||||
: _fcsShipment.shipmentNumber!,
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.black),
|
||||
),
|
||||
@@ -72,7 +72,7 @@ class _InvoiceShipmentListRowState extends State<InvoiceShipmentListRow> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0, top: 10),
|
||||
child: new Text(
|
||||
dateFormatter.format(_fcsShipment.cutoffDate),
|
||||
dateFormatter.format(_fcsShipment.cutoffDate!),
|
||||
style: new TextStyle(
|
||||
fontSize: 15.0, color: Colors.grey),
|
||||
),
|
||||
@@ -86,7 +86,7 @@ class _InvoiceShipmentListRowState extends State<InvoiceShipmentListRow> {
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: getStatus(_fcsShipment.status),
|
||||
child: getStatus(_fcsShipment.status!),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -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 )).forEach((s) {
|
||||
tableRows.add(InvoiceTableRow(
|
||||
data: s,
|
||||
invoiceDataType: InvoiceDataType.HandlingFeeType,
|
||||
@@ -95,7 +95,7 @@ class InvoiceTable extends StatelessWidget {
|
||||
invoiceDataType: InvoiceDataType.DeliveryFeeType,
|
||||
desc: "Delivery fee",
|
||||
rate: "",
|
||||
amount: "${invoice?.deliveryFee?.toStringAsFixed(2) ?? '0'}"));
|
||||
amount: "${invoice?.deliveryFee.toStringAsFixed(2) ?? '0'}"));
|
||||
|
||||
// // add discounts
|
||||
if (invoice!.discount != null) {
|
||||
@@ -104,7 +104,7 @@ class InvoiceTable extends StatelessWidget {
|
||||
invoiceDataType: InvoiceDataType.DiscountDataType,
|
||||
desc: "Discount\n${invoice?.discount?.code ?? ""}",
|
||||
rate: "",
|
||||
amount: "(${invoice?.discount?.amount?.toStringAsFixed(2) ?? ''})"));
|
||||
amount: "(${invoice?.discount?.amount.toStringAsFixed(2) ?? ''})"));
|
||||
}
|
||||
|
||||
return tableRows;
|
||||
|
||||
@@ -15,14 +15,14 @@ import 'package:path/path.dart' as Path;
|
||||
class InvoiceModel extends BaseModel {
|
||||
final log = Logger('InvoiceModel');
|
||||
|
||||
StreamSubscription<QuerySnapshot> listener;
|
||||
StreamSubscription<QuerySnapshot<Map<String, dynamic>>>? listener;
|
||||
|
||||
List<Invoice> _invoices = [];
|
||||
|
||||
List<Invoice> get invoices =>
|
||||
_selectedIndex == 1 ? _invoices : List<Invoice>.from(_paginator.values);
|
||||
|
||||
Paginator _paginator;
|
||||
late Paginator _paginator;
|
||||
|
||||
bool endOfPaidInvoices = false;
|
||||
bool isLoading = false;
|
||||
@@ -33,7 +33,7 @@ class InvoiceModel extends BaseModel {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
get selectedIndex => _selectedIndex;
|
||||
int get selectedIndex => _selectedIndex;
|
||||
|
||||
@override
|
||||
void privilegeChanged() {
|
||||
@@ -54,11 +54,11 @@ class InvoiceModel extends BaseModel {
|
||||
if (user == null) return;
|
||||
if (!forCustomer && !user.hasInvoices()) return;
|
||||
String path = "/$invoices_collection";
|
||||
if (listener != null) listener.cancel();
|
||||
if (listener != null) listener!.cancel();
|
||||
_invoices = [];
|
||||
|
||||
try {
|
||||
var q = Firestore.instance
|
||||
var q = FirebaseFirestore.instance
|
||||
.collection("$path")
|
||||
.where("status", isEqualTo: invoice_issued_status)
|
||||
.where("is_deleted", isEqualTo: false);
|
||||
@@ -69,9 +69,9 @@ class InvoiceModel extends BaseModel {
|
||||
|
||||
listener = q.snapshots().listen((QuerySnapshot snapshot) {
|
||||
_invoices.clear();
|
||||
_invoices = snapshot.documents.map((documentSnapshot) {
|
||||
var s = Invoice.fromMap(
|
||||
documentSnapshot.data, documentSnapshot.documentID);
|
||||
_invoices = snapshot.docs.map((documentSnapshot) {
|
||||
var s = Invoice.fromMap(documentSnapshot.data as Map<String, dynamic>,
|
||||
documentSnapshot.id);
|
||||
return s;
|
||||
}).toList();
|
||||
notifyListeners();
|
||||
@@ -85,7 +85,7 @@ class InvoiceModel extends BaseModel {
|
||||
if (!isCustomer) {
|
||||
if (user == null || !(user.hasInvoices())) throw "No privilege";
|
||||
}
|
||||
var pageQuery = Firestore.instance
|
||||
var pageQuery = FirebaseFirestore.instance
|
||||
.collection("/$invoices_collection")
|
||||
.where("is_deleted", isEqualTo: false);
|
||||
if (isCustomer) {
|
||||
@@ -105,7 +105,7 @@ class InvoiceModel extends BaseModel {
|
||||
return paginator;
|
||||
}
|
||||
|
||||
Future<void> loadMore({bool isCustomer}) async {
|
||||
Future<void> loadMore({bool? isCustomer}) async {
|
||||
if (_paginator.ended || _selectedIndex == 1)
|
||||
return; // when paid menu is not selected return
|
||||
isLoading = true;
|
||||
@@ -116,7 +116,7 @@ class InvoiceModel extends BaseModel {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> refresh({bool isCustomer}) async {
|
||||
Future<void> refresh({bool? isCustomer}) async {
|
||||
if (_selectedIndex == 1) return; // when paid menu is not selected return
|
||||
await _paginator.refresh(onFinished: () {
|
||||
notifyListeners();
|
||||
@@ -129,17 +129,17 @@ class InvoiceModel extends BaseModel {
|
||||
|
||||
logout() async {
|
||||
if (_paginator != null) _paginator.close();
|
||||
if (listener != null) await listener.cancel();
|
||||
if (listener != null) await listener!.cancel();
|
||||
_invoices = [];
|
||||
}
|
||||
|
||||
Future<Invoice> getInvoice(String id) async {
|
||||
Future<Invoice?> getInvoice(String id) async {
|
||||
String path = "/$invoices_collection";
|
||||
try {
|
||||
var ref = Firestore.instance.collection("$path").document(id);
|
||||
var snap = await ref.get(source: Source.server);
|
||||
var ref = FirebaseFirestore.instance.collection("$path").doc(id);
|
||||
var snap = await ref.get(const GetOptions(source: Source.server));
|
||||
if (snap.exists) {
|
||||
var s = Invoice.fromMap(snap.data, snap.documentID);
|
||||
var s = Invoice.fromMap(snap.data as Map<String, dynamic>, snap.id);
|
||||
return s;
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -50,9 +50,9 @@ class _PaymentPageState extends State<PaymentPage> {
|
||||
_loadInvoice() async {
|
||||
InvoiceModel invoiceModel =
|
||||
Provider.of<InvoiceModel>(context, listen: false);
|
||||
Invoice i = await invoiceModel.getInvoice(_invoice.id);
|
||||
Invoice? i = await invoiceModel.getInvoice(_invoice.id!);
|
||||
setState(() {
|
||||
_invoice = i;
|
||||
_invoice = i!;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class _PaymentPageState extends State<PaymentPage> {
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("pm_.title")),
|
||||
title: Text(AppTranslations.of(context)!.text("pm_.title")),
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
@@ -130,74 +130,73 @@ class _PaymentPageState extends State<PaymentPage> {
|
||||
List<Widget> dataRow = [];
|
||||
|
||||
dataRow = _invoice.payments.map((p) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
padding: const EdgeInsets.only(
|
||||
left: 5.0, right: 5.0, top: 5.0, bottom: 5.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey))),
|
||||
padding:
|
||||
const EdgeInsets.only(left: 5.0, right: 5.0, top: 5.0, bottom: 5.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Text(
|
||||
'${p.paymentDate != null ? dateFormatter.format(p.paymentDate!) : ""}'),
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
LocalImagePicker(
|
||||
key: ValueKey(p.id),
|
||||
enabled: false,
|
||||
initialImgUrl: p.paymentReceiptURL!,
|
||||
title: "Receipt",
|
||||
color: primaryColor,
|
||||
)
|
||||
],
|
||||
)),
|
||||
Expanded(
|
||||
flex: 1,
|
||||
child: Center(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Text(
|
||||
'${p.paymentDate != null ? dateFormatter.format(p.paymentDate) : ""}'),
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
LocalImagePicker(
|
||||
key: ValueKey(p.id),
|
||||
enabled: false,
|
||||
initialImgUrl: p.paymentReceiptURL,
|
||||
title: "Receipt",
|
||||
color: primaryColor,
|
||||
)
|
||||
],
|
||||
)),
|
||||
Expanded(
|
||||
children: [Text('\$ ${p.amount}'), Text('${p.status}')],
|
||||
))),
|
||||
widget.forCustomer!
|
||||
? Container()
|
||||
: Expanded(
|
||||
flex: 1,
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [Text('\$ ${p.amount}'), Text('${p.status}')],
|
||||
))),
|
||||
widget.forCustomer!
|
||||
? Container()
|
||||
: Expanded(
|
||||
flex: 1,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: p.status == payment_pending_status
|
||||
? [
|
||||
InkWell(
|
||||
onTap: () => _confirm(p),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
Icons.check,
|
||||
color: primaryColor,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: p.status == payment_pending_status
|
||||
? [
|
||||
InkWell(
|
||||
onTap: () => _confirm(p),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
Icons.check,
|
||||
color: primaryColor,
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => _cancel(p),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(Icons.close,
|
||||
color: primaryColor),
|
||||
),
|
||||
),
|
||||
]
|
||||
: [],
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList() ;
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => _cancel(p),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Icon(Icons.close, color: primaryColor),
|
||||
),
|
||||
),
|
||||
]
|
||||
: [],
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
dataRow.insert(
|
||||
0,
|
||||
|
||||
@@ -154,7 +154,7 @@ class _PaymentPageEditState extends State<PaymentPageEdit> {
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("pm_.title")),
|
||||
title: Text(AppTranslations.of(context)!.text("pm_.title")),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
@@ -189,7 +189,7 @@ class _PaymentPageEditState extends State<PaymentPageEdit> {
|
||||
_widget = initialImage();
|
||||
} else {
|
||||
_widget = InkWell(
|
||||
child: Image.asset(widget.receipt!.fileUrl, fit: BoxFit.cover),
|
||||
child: Image.asset(widget.receipt!.fileUrl!, fit: BoxFit.cover),
|
||||
onTap: () {},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user