diff --git a/lib/pages/invoice/box_addition.dart b/lib/pages/invoice/box_addition.dart index 2bf0698..805979f 100644 --- a/lib/pages/invoice/box_addition.dart +++ b/lib/pages/invoice/box_addition.dart @@ -45,7 +45,7 @@ class _BoxAdditionState extends State { 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( diff --git a/lib/pages/invoice/editor/invoice_carton_table.dart b/lib/pages/invoice/editor/invoice_carton_table.dart index 8af98b8..6faf7c8 100644 --- a/lib/pages/invoice/editor/invoice_carton_table.dart +++ b/lib/pages/invoice/editor/invoice_carton_table.dart @@ -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: [ 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, ), ], diff --git a/lib/pages/invoice/editor/invoice_discount_list.dart b/lib/pages/invoice/editor/invoice_discount_list.dart index 75a348f..3381a3e 100644 --- a/lib/pages/invoice/editor/invoice_discount_list.dart +++ b/lib/pages/invoice/editor/invoice_discount_list.dart @@ -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( diff --git a/lib/pages/invoice/editor/invoice_editor.dart b/lib/pages/invoice/editor/invoice_editor.dart index 32ddbd3..b40c834 100644 --- a/lib/pages/invoice/editor/invoice_editor.dart +++ b/lib/pages/invoice/editor/invoice_editor.dart @@ -91,7 +91,7 @@ class _InvoiceEditorState extends State { _loadCartons() async { CartonModel cartonModel = Provider.of(context, listen: false); List 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 { ShipmentModel shipmentModel = Provider.of(context, listen: false); List 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 { _loadDiscount() async { DiscountModel discountModel = Provider.of(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 { 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 { 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; diff --git a/lib/pages/invoice/editor/invoice_handling_fee_list.dart b/lib/pages/invoice/editor/invoice_handling_fee_list.dart index 8f771c4..5ee937d 100644 --- a/lib/pages/invoice/editor/invoice_handling_fee_list.dart +++ b/lib/pages/invoice/editor/invoice_handling_fee_list.dart @@ -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( diff --git a/lib/pages/invoice/invoice_customer_list.dart b/lib/pages/invoice/invoice_customer_list.dart index 8feee77..3df5226 100644 --- a/lib/pages/invoice/invoice_customer_list.dart +++ b/lib/pages/invoice/invoice_customer_list.dart @@ -33,7 +33,7 @@ class _InvoiceCustomerListState extends State { _load() async { CustomerModel customerModel = Provider.of(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 { 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 { Padding( padding: const EdgeInsets.only(top: 2.0), child: new Text( - customer.phoneNumber, + customer.phoneNumber!, style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), diff --git a/lib/pages/invoice/invoice_info.dart b/lib/pages/invoice/invoice_info.dart index e4f8777..ba3adbc 100644 --- a/lib/pages/invoice/invoice_info.dart +++ b/lib/pages/invoice/invoice_info.dart @@ -118,7 +118,7 @@ class _InvoiceInfoState extends State { 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 { ); final paymentMethodBox = DisplayText( labelTextKey: "invoice.payment_method", - text: _invoice!.paymentMethod.name, + text: _invoice!.paymentMethod!.name, ); final cancelBtn = LocalButton( diff --git a/lib/pages/invoice/invoice_list_row.dart b/lib/pages/invoice/invoice_list_row.dart index 3009c0d..1ffc7b1 100644 --- a/lib/pages/invoice/invoice_list_row.dart +++ b/lib/pages/invoice/invoice_list_row.dart @@ -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), ) diff --git a/lib/pages/invoice/invoice_shipment_list_row.dart b/lib/pages/invoice/invoice_shipment_list_row.dart index 21cf4aa..e77cc75 100644 --- a/lib/pages/invoice/invoice_shipment_list_row.dart +++ b/lib/pages/invoice/invoice_shipment_list_row.dart @@ -64,7 +64,7 @@ class _InvoiceShipmentListRowState extends State { 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 { 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 { ), Padding( padding: const EdgeInsets.all(0), - child: getStatus(_fcsShipment.status), + child: getStatus(_fcsShipment.status!), ), ], ), diff --git a/lib/pages/invoice/invoice_table.dart b/lib/pages/invoice/invoice_table.dart index c7b1cc7..46ed34b 100644 --- a/lib/pages/invoice/invoice_table.dart +++ b/lib/pages/invoice/invoice_table.dart @@ -61,16 +61,16 @@ class InvoiceTable extends StatelessWidget { List getTableRows() { List tableRows = []; // add cargo types - List _cargoTypes = invoice!.getCargoTypes(rate!) ?? []; + List _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; diff --git a/lib/pages/invoice/model/invoice_model.dart b/lib/pages/invoice/model/invoice_model.dart index f8f7758..2ad13f8 100644 --- a/lib/pages/invoice/model/invoice_model.dart +++ b/lib/pages/invoice/model/invoice_model.dart @@ -15,14 +15,14 @@ import 'package:path/path.dart' as Path; class InvoiceModel extends BaseModel { final log = Logger('InvoiceModel'); - StreamSubscription listener; + StreamSubscription>>? listener; List _invoices = []; List get invoices => _selectedIndex == 1 ? _invoices : List.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, + 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 loadMore({bool isCustomer}) async { + Future 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 refresh({bool isCustomer}) async { + Future 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 getInvoice(String id) async { + Future 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, snap.id); return s; } } catch (e) { diff --git a/lib/pages/invoice/payment/payment_page.dart b/lib/pages/invoice/payment/payment_page.dart index 641de33..c17e966 100644 --- a/lib/pages/invoice/payment/payment_page.dart +++ b/lib/pages/invoice/payment/payment_page.dart @@ -50,9 +50,9 @@ class _PaymentPageState extends State { _loadInvoice() async { InvoiceModel invoiceModel = Provider.of(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 { 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 { List 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, diff --git a/lib/pages/invoice/payment/payment_page_edit.dart b/lib/pages/invoice/payment/payment_page_edit.dart index 19aa12c..098a354 100644 --- a/lib/pages/invoice/payment/payment_page_edit.dart +++ b/lib/pages/invoice/payment/payment_page_edit.dart @@ -154,7 +154,7 @@ class _PaymentPageEditState extends State { 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 { _widget = initialImage(); } else { _widget = InkWell( - child: Image.asset(widget.receipt!.fileUrl, fit: BoxFit.cover), + child: Image.asset(widget.receipt!.fileUrl!, fit: BoxFit.cover), onTap: () {}, ); } diff --git a/lib/pages/market/market_editor.dart b/lib/pages/market/market_editor.dart index 92f4483..9efdd9e 100644 --- a/lib/pages/market/market_editor.dart +++ b/lib/pages/market/market_editor.dart @@ -35,7 +35,7 @@ class _MarketEditorState extends State { children: [ Expanded( child: new Text( - p.name, + p.name ?? "", style: TextStyle( fontSize: 15.0, ), @@ -117,7 +117,7 @@ class _MarketEditorState extends State { }); MarketModel marketModel = Provider.of(context, listen: false); try { - await marketModel.deleteMarket(market.id); + await marketModel.deleteMarket(market.id!); } catch (e) { showMsgDialog(context, "Error", e.toString()); } finally { diff --git a/lib/pages/market/model/market_model.dart b/lib/pages/market/model/market_model.dart index c97cbdb..7f45b50 100644 --- a/lib/pages/market/model/market_model.dart +++ b/lib/pages/market/model/market_model.dart @@ -20,14 +20,14 @@ class MarketModel extends BaseModel { try { if (listener != null) listener.cancel(); - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("/$config_collection/$setting_doc_id/$markets_collection") .snapshots() .listen((QuerySnapshot snapshot) { markets.clear(); - markets = snapshot.documents.map((documentSnapshot) { + markets = snapshot.docs.map((documentSnapshot) { var user = Market.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return user; }).toList(); notifyListeners(); diff --git a/lib/pages/package/model/package_model.dart b/lib/pages/package/model/package_model.dart index f826ceb..0b53d77 100644 --- a/lib/pages/package/model/package_model.dart +++ b/lib/pages/package/model/package_model.dart @@ -16,9 +16,9 @@ import 'package:path/path.dart' as Path; class PackageModel extends BaseModel { final log = Logger('PackageModel'); - PaginatorListener packages; - PaginatorListener customerPackages; - PaginatorListener activePackages; + PaginatorListener? packages; + PaginatorListener? customerPackages; + PaginatorListener? activePackages; bool isLoading = false; int _menuSelectedIndex = 1; @@ -32,7 +32,7 @@ class PackageModel extends BaseModel { notifyListeners(); } - get menuSelectedIndex => _menuSelectedIndex; + int get menuSelectedIndex => _menuSelectedIndex; void privilegeChanged() { if (user != null) { @@ -63,9 +63,9 @@ class PackageModel extends BaseModel { @override logout() async { - if (customerPackages != null) customerPackages.close(); - if (packages != null) packages.close(); - if (activePackages != null) activePackages.close(); + if (customerPackages != null) customerPackages!.close(); + if (packages != null) packages!.close(); + if (activePackages != null) activePackages!.close(); } Future _loadPackages(bool isDelivered) async { @@ -75,15 +75,15 @@ class PackageModel extends BaseModel { String path = "/$packages_collection"; try { - Query listenerQuery = Firestore.instance + Query listenerQuery = FirebaseFirestore.instance .collection(path) .where("is_delivered", isEqualTo: isDelivered); - Query pageQuery = Firestore.instance + Query pageQuery = FirebaseFirestore.instance .collection(path) .where("is_delivered", isEqualTo: isDelivered); pageQuery = pageQuery.orderBy("update_time", descending: true); - packages.refresh(listeningQuery: listenerQuery, pageQuery: pageQuery); + packages!.refresh(listeningQuery: listenerQuery, pageQuery: pageQuery); } catch (e) { log.warning("Error!! $e"); } @@ -94,17 +94,17 @@ class PackageModel extends BaseModel { String path = "/$packages_collection"; try { - Query listenerQuery = Firestore.instance + Query listenerQuery = FirebaseFirestore.instance .collection(path) .where("is_delivered", isEqualTo: isDelivered) .where("user_id", isEqualTo: user.id); - Query pageQuery = Firestore.instance + Query pageQuery = FirebaseFirestore.instance .collection(path) .where("is_delivered", isEqualTo: isDelivered) .where("user_id", isEqualTo: user.id) .orderBy("update_time", descending: true); - customerPackages.refresh( + customerPackages!.refresh( listeningQuery: listenerQuery, pageQuery: pageQuery); } catch (e) { log.warning("Error!! $e"); @@ -118,29 +118,30 @@ class PackageModel extends BaseModel { String path = "/$packages_collection"; try { - Query listenerQuery = Firestore.instance + Query listenerQuery = FirebaseFirestore.instance .collection(path) .where("is_delivered", isEqualTo: false); - Query pageQuery = Firestore.instance + Query pageQuery = FirebaseFirestore.instance .collection(path) .where("is_delivered", isEqualTo: false); pageQuery = pageQuery.orderBy("update_time", descending: true); - activePackages.refresh( + activePackages!.refresh( listeningQuery: listenerQuery, pageQuery: pageQuery); } catch (e) { log.warning("Error!! $e"); } } - Future getPackage(String id) async { + Future getPackage(String id) async { if (user == null) return null; String path = "/$packages_collection"; try { DocumentSnapshot snap = - await Firestore.instance.collection("$path").document(id).get(); + await FirebaseFirestore.instance.collection("$path").doc(id).get(); if (snap.exists) { - var package = Package.fromMap(snap.data, snap.documentID); + var package = + Package.fromMap(snap.data as Map, snap.id); return package; } } catch (e) { @@ -149,18 +150,18 @@ class PackageModel extends BaseModel { return null; } - Future getPackageByTrackingID(String trackingID) async { + Future getPackageByTrackingID(String trackingID) async { if (user == null) return null; String path = "/$packages_collection"; try { - var snaps = await Firestore.instance + var snaps = await FirebaseFirestore.instance .collection("$path") .where("tracking_id", isEqualTo: trackingID) .where("is_deleted", isEqualTo: false) - .getDocuments(source: Source.server); - if (snaps.documents.length == 1) { - var snap = snaps.documents[0]; - var package = Package.fromMap(snap.data, snap.documentID); + .get(const GetOptions(source: Source.server)); + if (snaps.docs.length == 1) { + var snap = snaps.docs[0]; + var package = Package.fromMap(snap.data as Map, snap.id); return package; } } catch (e) { @@ -169,35 +170,35 @@ class PackageModel extends BaseModel { return null; } - Future lookupPackage(String trackingID) async { + Future lookupPackage(String trackingID) async { if (user == null) return null; String path = "/$packages_collection"; try { - var qsnap = await Firestore.instance + var qsnap = await FirebaseFirestore.instance .collection("$path") .where("tracking_id", isEqualTo: trackingID) .where("has_user_id", isEqualTo: false) .where("is_deleted", isEqualTo: false) - .getDocuments(source: Source.server); - if (qsnap.documents.length > 0) { - var snap = qsnap.documents[0]; + .get(const GetOptions(source: Source.server)); + if (qsnap.docs.length > 0) { + var snap = qsnap.docs[0]; if (snap.exists) { - var package = Package.fromMap(snap.data, snap.documentID); + var package = Package.fromMap(snap.data as Map, snap.id); return package; } } - qsnap = await Firestore.instance + qsnap = await FirebaseFirestore.instance .collection("$path") .where("tracking_id", isEqualTo: trackingID) .where("user_id", isEqualTo: user.id) .where("is_deleted", isEqualTo: false) - .getDocuments(source: Source.server); - if (qsnap.documents.length > 0) { - var snap = qsnap.documents[0]; + .get(const GetOptions(source: Source.server)); + if (qsnap.docs.length > 0) { + var snap = qsnap.docs[0]; if (snap.exists) { - var package = Package.fromMap(snap.data, snap.documentID); + var package = Package.fromMap(snap.data as Map, snap.id); return package; } } @@ -210,15 +211,15 @@ class PackageModel extends BaseModel { Future> getPackages(String userID, List status) async { List packages = []; try { - var snaps = await Firestore.instance + var snaps = await FirebaseFirestore.instance .collection("/$packages_collection") .where("status", whereIn: status) .where("user_id", isEqualTo: userID) .where("is_deleted", isEqualTo: false) - .getDocuments(source: Source.server); - packages = snaps.documents.map((documentSnapshot) { + .get(const GetOptions(source: Source.server)); + packages = snaps.docs.map((documentSnapshot) { var p = - Package.fromMap(documentSnapshot.data, documentSnapshot.documentID); + Package.fromMap(documentSnapshot.data as Map, documentSnapshot.id); return p; }).toList(); } catch (e) { @@ -235,22 +236,22 @@ class PackageModel extends BaseModel { Future> packages = Services.instance.packageService.searchPackage(term); - Future> packagesFTS = + Future?> packagesFTS = Services.instance.packageService.ftsSearchPackage(term); // Package pkg = await getPackageByTrackingID(term); // if (pkg != null && !packages.contains(pkg)) { // packages.insert(0, pkg); // } List pkgs = await packages; - List ftsPkgs = await packagesFTS; - pkgs.addAll(ftsPkgs); + List? ftsPkgs = await packagesFTS; + pkgs.addAll(ftsPkgs!); final seen = Set(); return pkgs.where((e) => seen.add(e)).toList(); } Future createPackages(User user, List packages) { return Services.instance.packageService - .createPackages(packages, user.fcsID); + .createPackages(packages, user.fcsID!); } Future createReceiving( @@ -370,10 +371,10 @@ class PackageModel extends BaseModel { Future changeDeliveryAddress( Package package, DeliveryAddress deliveryAddress) { return Services.instance.packageService - .changeDeliveryAddress(package.id, deliveryAddress.id); + .changeDeliveryAddress(package.id!, deliveryAddress.id!); } Future packageReturn(Package package) { - return Services.instance.packageService.packageReturn(package.id); + return Services.instance.packageService.packageReturn(package.id!); } } diff --git a/lib/pages/widgets/delivery_address_selection.dart b/lib/pages/widgets/delivery_address_selection.dart index c21a376..1f1b0a6 100644 --- a/lib/pages/widgets/delivery_address_selection.dart +++ b/lib/pages/widgets/delivery_address_selection.dart @@ -38,7 +38,7 @@ class _DeliveryAddressSelectionState extends State { Provider.of(context, listen: false); var deliveryAddresses = - await addressModel.getDeliveryAddresses(widget.user!.id); + await addressModel.getDeliveryAddresses(widget.user!.id!); setState(() { this._deliveryAddresses = deliveryAddresses; }); @@ -64,7 +64,7 @@ class _DeliveryAddressSelectionState extends State { bool updated = await Navigator.of(context).push(CupertinoPageRoute( builder: (context) => DeliveryAddressEditor(user: widget.user))); - if (updated ?? false) { + if (updated) { _getDeliverAddresses(); } }, @@ -117,7 +117,7 @@ class _DeliveryAddressSelectionState extends State { bool updated = await Navigator.of(context).push(CupertinoPageRoute( builder: (context) => DeliveryAddressEditor( user: widget.user, deliveryAddress: deliveryAddress))); - if (updated ?? false) { + if (updated) { _getDeliverAddresses(); } } diff --git a/lib/pages/widgets/discount_dropdown.dart b/lib/pages/widgets/discount_dropdown.dart index b4be510..8f00fa7 100644 --- a/lib/pages/widgets/discount_dropdown.dart +++ b/lib/pages/widgets/discount_dropdown.dart @@ -53,7 +53,8 @@ class DiscountDropdown extends StatelessWidget { items: values!.map>((T value) { return DropdownMenuItem( value: value, - child: Text(value == null ? "" : (value as Discount).code, + child: Text( + value == null ? "" : (value as Discount).code!, overflow: TextOverflow.ellipsis, style: TextStyle(color: primaryColor)), ); diff --git a/lib/pages/widgets/my_data_table.dart b/lib/pages/widgets/my_data_table.dart index 52932b0..3015c50 100644 --- a/lib/pages/widgets/my_data_table.dart +++ b/lib/pages/widgets/my_data_table.dart @@ -20,7 +20,7 @@ class MyDataColumn { /// /// The [label] argument must not be null. const MyDataColumn({ - @required this.label, + required this.label, this.tooltip, this.numeric = false, this.onSort, @@ -40,7 +40,7 @@ class MyDataColumn { /// This is a longer description of the column heading, for cases /// where the heading might have been abbreviated to keep the column /// width to a reasonable size. - final String tooltip; + final String? tooltip; /// Whether this column represents numeric data or not. /// @@ -53,7 +53,7 @@ class MyDataColumn { /// If null, the column will not be considered sortable. /// /// See [MyDataTable.sortColumnIndex] and [MyDataTable.sortAscending]. - final MyDataColumnSortCallback onSort; + final MyDataColumnSortCallback? onSort; bool get _debugInteractive => onSort != null; } diff --git a/lib/pages/widgets/show_multiple_img.dart b/lib/pages/widgets/show_multiple_img.dart index f94e81d..17e0821 100644 --- a/lib/pages/widgets/show_multiple_img.dart +++ b/lib/pages/widgets/show_multiple_img.dart @@ -8,14 +8,14 @@ class ShowMultiImage extends StatefulWidget { final List displayImageSources; final int initialPage; const ShowMultiImage( - {Key key, this.displayImageSources, this.initialPage = 0}) + {Key? key, required this.displayImageSources, this.initialPage = 0}) : super(key: key); @override _ShowMultiImageState createState() => _ShowMultiImageState(); } class _ShowMultiImageState extends State { - PageController pageController; + late PageController pageController; @override void initState() { pageController = PageController(initialPage: widget.initialPage); @@ -58,7 +58,7 @@ class _ShowMultiImageState extends State { value: event == null ? 0 : event.cumulativeBytesLoaded / - event.expectedTotalBytes, + event.expectedTotalBytes!, ), ), ), diff --git a/lib/pages/widgets/status_tree.dart b/lib/pages/widgets/status_tree.dart index 27e2e49..a01cb7e 100644 --- a/lib/pages/widgets/status_tree.dart +++ b/lib/pages/widgets/status_tree.dart @@ -4,7 +4,7 @@ import 'package:fcs/domain/vo/shipment_status.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 'package:timeline_list/timeline.dart'; import 'package:timeline_list/timeline_model.dart'; @@ -12,10 +12,10 @@ import 'package:timeline_list/timeline_model.dart'; var dateFormatter = new DateFormat('dd MMM yyyy'); class StatusTree extends StatelessWidget { - final List shipmentHistory; - final String currentStatus; + final List? shipmentHistory; + final String? currentStatus; - const StatusTree({Key key, this.shipmentHistory, this.currentStatus}) + const StatusTree({Key? key, this.shipmentHistory, this.currentStatus}) : super(key: key); @override Widget build(BuildContext context) { @@ -39,7 +39,7 @@ class StatusTree extends StatelessWidget { if (shipmentHistory == null || currentStatus == null) return []; bool isPacked = currentStatus != package_received_status && currentStatus != package_processed_status; - return shipmentHistory + return shipmentHistory! .map((e) => TimelineModel( Padding( padding: const EdgeInsets.all(18.0), @@ -48,17 +48,17 @@ class StatusTree extends StatelessWidget { children: [ Text(e.status, style: TextStyle( - color: e.done ? primaryColor : Colors.grey, + color: e.done! ? primaryColor : Colors.grey, fontSize: 16, fontWeight: FontWeight.bold)), - e.done || isPacked + e.done! || isPacked ? Text(dateFormatter.format(e.date)) : Container(), - e.staffName == null ? Container() : Text(e.staffName) + e.staffName == null ? Container() : Text(e.staffName!) ], ), ), - iconBackground: e.done ? primaryColor : Colors.grey, + iconBackground: e.done! ? primaryColor : Colors.grey, icon: Icon( e.status == "shipped" ? Ionicons.ios_airplane diff --git a/lib/pages/widgets/task_button.dart b/lib/pages/widgets/task_button.dart index 5ad828c..638cc91 100644 --- a/lib/pages/widgets/task_button.dart +++ b/lib/pages/widgets/task_button.dart @@ -9,11 +9,11 @@ typedef BtnCallback(); /// TaskButton is used to navigate to eash task class TaskButton extends StatelessWidget { - final String titleKey; - final IconData icon; - final BtnCallback btnCallback; + final String? titleKey; + final IconData? icon; + final BtnCallback? btnCallback; - const TaskButton(this.titleKey, {Key key, this.icon, this.btnCallback}) + const TaskButton(this.titleKey, {Key? key, this.icon, this.btnCallback}) : super(key: key); @override @@ -45,7 +45,7 @@ class TaskButton extends StatelessWidget { Container( height: 45, alignment: Alignment.topCenter, - child: Text(AppTranslations.of(context).text(titleKey), + child: Text(AppTranslations.of(context)!.text(titleKey!), textAlign: TextAlign.center, style: languageModel.isEng ? TextStyle( diff --git a/lib/pages/widgets/title_with_add_button.dart b/lib/pages/widgets/title_with_add_button.dart index c006f35..e988f4e 100644 --- a/lib/pages/widgets/title_with_add_button.dart +++ b/lib/pages/widgets/title_with_add_button.dart @@ -6,11 +6,11 @@ import 'package:flutter/material.dart'; import 'callbacks.dart'; class TitleWithAddButton extends StatelessWidget { - final IconData iconData; - final String titleKey; - final OnTap onTap; + final IconData? iconData; + final String? titleKey; + final OnTap? onTap; - const TitleWithAddButton({Key key, this.iconData, this.titleKey, this.onTap}) + const TitleWithAddButton({Key? key, this.iconData, this.titleKey, this.onTap}) : super(key: key); @override @@ -28,7 +28,7 @@ class TitleWithAddButton extends StatelessWidget { ), LocalText( context, - titleKey, + titleKey!, color: Colors.black54, fontSize: 20, ) @@ -40,7 +40,7 @@ class TitleWithAddButton extends StatelessWidget { : Padding( padding: const EdgeInsets.only(right: 0), child: IconButton( - onPressed: () => onTap(), + onPressed: () => onTap!(), icon: Icon( Icons.add_circle, color: primaryColor, diff --git a/pubspec.yaml b/pubspec.yaml index 557e00e..3153f46 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: cupertino_icons: ^1.0.3 firebase_core: ^1.5.0 - cloud_firestore: ^2.5.0 + cloud_firestore: ^2.5.2 firebase_storage: ^10.0.2 firebase_auth: "^3.0.2" # firebase_messaging: ^6.0.15