diff --git a/lib/pages/delivery/delivery_info.dart b/lib/pages/delivery/delivery_info.dart index 0f3e423..fef0d5e 100644 --- a/lib/pages/delivery/delivery_info.dart +++ b/lib/pages/delivery/delivery_info.dart @@ -22,6 +22,7 @@ import 'package:fcs/pages/widgets/local_title.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -59,9 +60,8 @@ class _DeliveryInfoState extends State { @override void initState() { super.initState(); - if(widget.box != null) - _box = widget.box!; - _selectedCartonType = _box.cartonType; + if (widget.box != null) _box = widget.box!; + _selectedCartonType = _box.cartonType ?? ''; //for shipment weight volumetricRatio = Provider.of(context, listen: false) @@ -80,7 +80,7 @@ class _DeliveryInfoState extends State { _heightController.text = _box.height.toString(); _lengthController.text = _box.length.toString(); _cargoTypes = _box.cargoTypes; - _deliveryAddress = _box.deliveryAddress; + _deliveryAddress = _box.deliveryAddress!; isMixBox = _box.cartonType == carton_mix_box; isFromShipments = _box.cartonType == carton_from_shipments; isFromPackages = _box.cartonType == carton_from_packages; @@ -96,7 +96,7 @@ class _DeliveryInfoState extends State { if (_box.cartonType == carton_from_packages && _box.userID == null) return; PackageModel packageModel = Provider.of(context, listen: false); - List packages = await packageModel.getPackages(_box.userID, [ + List packages = await packageModel.getPackages(_box.userID!, [ package_processed_status, package_packed_status, package_shipped_status, @@ -135,8 +135,9 @@ class _DeliveryInfoState extends State { final cartonTypeBox = LocalRadioButtons( readOnly: true, values: cartonModel.cartonTypesInfo, - selectedValue: - _box.isShipmentCarton ? carton_from_shipments : _box.cartonType); + selectedValue: (_box.isShipmentCarton ?? false) + ? carton_from_shipments + : _box.cartonType); final shipmentBox = DisplayText( text: _box.fcsShipmentNumber, labelTextKey: "box.fcs_shipment_num", @@ -173,11 +174,11 @@ class _DeliveryInfoState extends State { children: [ Expanded( child: new Text( - _selectedShipmentBox.shipmentNumber, + _selectedShipmentBox.shipmentNumber ?? "", style: textStyle, )), new Text( - _selectedShipmentBox.desc, + _selectedShipmentBox.desc ?? "", style: textStyle, ), ], @@ -214,7 +215,7 @@ class _DeliveryInfoState extends State { ); final shipmentWeightBox = DisplayText( - text: shipmentWeight.toStringAsFixed(0) : "", + text: shipmentWeight.toStringAsFixed(0), labelTextKey: "box.shipment_weight", iconData: MaterialCommunityIcons.weight, ); diff --git a/lib/pages/delivery/delivery_list_row.dart b/lib/pages/delivery/delivery_list_row.dart index d688e2a..c77f115 100644 --- a/lib/pages/delivery/delivery_list_row.dart +++ b/lib/pages/delivery/delivery_list_row.dart @@ -3,6 +3,7 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; import 'delivery_info.dart'; diff --git a/lib/pages/delivery/model/delivery_model.dart b/lib/pages/delivery/model/delivery_model.dart index b200684..235f820 100644 --- a/lib/pages/delivery/model/delivery_model.dart +++ b/lib/pages/delivery/model/delivery_model.dart @@ -14,18 +14,18 @@ class DeliveryModel extends BaseModel { List get cartons => _selectedIndex == 1 ? _cartons : List.from(_delivered.values); - Paginator _delivered; + late Paginator _delivered; int _selectedIndex = 1; bool isLoading = false; List _cartons = []; - StreamSubscription listener; + StreamSubscription? listener; set selectedIndex(int index) { _selectedIndex = index; notifyListeners(); } - get selectedIndex => _selectedIndex; + int get selectedIndex => _selectedIndex; initData() { _selectedIndex = 1; @@ -37,12 +37,12 @@ class DeliveryModel extends BaseModel { } Future _loadCartons() async { - if (user == null || !user.hasDeliveries()) return; + if (user == null || !user!.hasDeliveries()) return; String path = "/$cartons_collection/"; - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); _cartons = []; try { - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("$path") .where("status", isEqualTo: carton_shipped_status) .where("carton_type", whereIn: [ @@ -55,9 +55,9 @@ class DeliveryModel extends BaseModel { .snapshots() .listen((QuerySnapshot snapshot) { _cartons.clear(); - _cartons = snapshot.documents.map((documentSnapshot) { + _cartons = snapshot.docs.map((documentSnapshot) { var s = Carton.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return s; }).toList(); notifyListeners(); @@ -68,9 +68,9 @@ class DeliveryModel extends BaseModel { } Paginator _getDelivered() { - if (user == null || !user.hasDeliveries()) return null; + if (user == null || !user!.hasDeliveries()) throw "No Privilege"; - var pageQuery = Firestore.instance + var pageQuery = FirebaseFirestore.instance .collection("/$cartons_collection") .where("is_delivered", isEqualTo: true) .where("status", whereIn: [carton_delivered_status]).where("is_deleted", @@ -105,7 +105,7 @@ class DeliveryModel extends BaseModel { @override logout() async { - if (listener != null) await listener.cancel(); + if (listener != null) await listener!.cancel(); if (_delivered != null) _delivered.close(); _cartons = []; } diff --git a/lib/pages/delivery_address/delivery_address_editor.dart b/lib/pages/delivery_address/delivery_address_editor.dart index 336adeb..aa84ba2 100644 --- a/lib/pages/delivery_address/delivery_address_editor.dart +++ b/lib/pages/delivery_address/delivery_address_editor.dart @@ -8,6 +8,7 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; class DeliveryAddressEditor extends StatefulWidget { @@ -38,12 +39,12 @@ class _DeliveryAddressEditorState extends State { if (widget.deliveryAddress != null) { _isNew = false; _deliveryAddress = widget.deliveryAddress!; - _nameController.text = _deliveryAddress.fullName; - _address1Controller.text = _deliveryAddress.addressLine1; - _address2Controller.text = _deliveryAddress.addressLine2; - _cityController.text = _deliveryAddress.city; - _stateController.text = _deliveryAddress.state; - _phoneController.text = _deliveryAddress.phoneNumber; + _nameController.text = _deliveryAddress.fullName ?? ""; + _address1Controller.text = _deliveryAddress.addressLine1 ?? ""; + _address2Controller.text = _deliveryAddress.addressLine2 ?? ""; + _cityController.text = _deliveryAddress.city ?? ""; + _stateController.text = _deliveryAddress.state ?? ""; + _phoneController.text = _deliveryAddress.phoneNumber?? ""; } else { _cityController.text = "Yangon"; _stateController.text = "Yangon"; diff --git a/lib/pages/delivery_address/delivery_address_row.dart b/lib/pages/delivery_address/delivery_address_row.dart index fd8f576..c6e248c 100644 --- a/lib/pages/delivery_address/delivery_address_row.dart +++ b/lib/pages/delivery_address/delivery_address_row.dart @@ -3,6 +3,7 @@ import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; typedef SelectionCallback(DeliveryAddress deliveryAddress); diff --git a/lib/pages/delivery_address/model/delivery_address_model.dart b/lib/pages/delivery_address/model/delivery_address_model.dart index a344c82..0ccbf33 100644 --- a/lib/pages/delivery_address/model/delivery_address_model.dart +++ b/lib/pages/delivery_address/model/delivery_address_model.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'package:barcode_scan2/gen/protos/protos.pb.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:fcs/data/services/services.dart'; import 'package:fcs/domain/vo/delivery_address.dart'; @@ -10,13 +11,13 @@ class DeliveryAddressModel extends BaseModel { final log = Logger('FcsShipmentModel'); List deliveryAddresses = []; - StreamSubscription listener; + StreamSubscription? listener; DeliveryAddress get defalutAddress => - deliveryAddresses.firstWhere((e) => e.isDefault, orElse: () => null); + deliveryAddresses.firstWhere((e) => e.isDefault, orElse: () => DeliveryAddress()); DeliveryAddress getLocalDeliveryAddress(String id) => - deliveryAddresses.firstWhere((e) => e.id == id, orElse: () => null); + deliveryAddresses.firstWhere((e) => e.id == id, orElse: () => DeliveryAddress()); @override void privilegeChanged() { @@ -26,26 +27,26 @@ class DeliveryAddressModel extends BaseModel { @override logout() async { - if (listener != null) await listener.cancel(); + if (listener != null) await listener!.cancel(); deliveryAddresses = []; } Future _loadDeliveryAddresses() async { if (user == null) return; String path = "$delivery_address_collection/"; - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); deliveryAddresses = []; try { - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection('users') - .document("${user.id}") + .doc("${user!.id}") .collection("$path") .snapshots() .listen((QuerySnapshot snapshot) { deliveryAddresses.clear(); - deliveryAddresses = snapshot.documents.map((documentSnapshot) { + deliveryAddresses = snapshot.docs.map((documentSnapshot) { var s = DeliveryAddress.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return s; }).toList(); notifyListeners(); @@ -56,9 +57,9 @@ class DeliveryAddressModel extends BaseModel { } Future getDeliveryAddress(String id) async { - String path = "/$user_collection/${user.id}/$delivery_address_collection"; - var snap = await Firestore.instance.collection(path).document(id).get(); - return DeliveryAddress.fromMap(snap.data, snap.documentID); + String path = "/$user_collection/${user!.id}/$delivery_address_collection"; + var snap = await FirebaseFirestore.instance.collection(path).doc(id).get(); + return DeliveryAddress.fromMap(snap.data as Map, snap.id); } void initUser(user) { @@ -87,14 +88,14 @@ class DeliveryAddressModel extends BaseModel { Future> getDeliveryAddresses(String userID) async { String path = "$delivery_address_collection/"; - var querySnap = await Firestore.instance + var querySnap = await FirebaseFirestore.instance .collection('users') - .document("$userID") + .doc("$userID") .collection("$path") .orderBy("full_name") - .getDocuments(); - return querySnap.documents - .map((e) => DeliveryAddress.fromMap(e.data, e.documentID)) + .get(); + return querySnap.docs + .map((e) => DeliveryAddress.fromMap(e.data as Map, e.id)) .toList(); } } diff --git a/lib/pages/discount/discount_editor.dart b/lib/pages/discount/discount_editor.dart index 742e9c0..3b66baf 100644 --- a/lib/pages/discount/discount_editor.dart +++ b/lib/pages/discount/discount_editor.dart @@ -9,6 +9,7 @@ import 'package:fcs/pages/widgets/input_text.dart'; import 'package:fcs/pages/widgets/progress.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; @@ -36,11 +37,11 @@ class _DiscountEditorState extends State { super.initState(); if (widget.discount != null) { _discount = widget.discount!; - _codeController.text = _discount.code; + _codeController.text = _discount.code ?? ""; _amountController.text = _discount.amount.toStringAsFixed(2); - _statusController.text = _discount.status; - customerName = _discount.customerName; - customerId = _discount.customerId; + _statusController.text = _discount.status ?? ''; + customerName = _discount.customerName ?? ""; + customerId = _discount.customerId ?? ""; } else { _isNew = true; } @@ -76,8 +77,8 @@ class _DiscountEditorState extends State { icon: Icon(Icons.search, color: primaryColor), onPressed: () => searchUser(context, onUserSelect: (u) { setState(() { - customerId = u.id; - customerName = u.name; + customerId = u.id ?? ""; + customerName = u.name ?? ""; }); },popPage: true)), ], diff --git a/lib/pages/discount/discount_list_row.dart b/lib/pages/discount/discount_list_row.dart index 473b5b3..b2702b2 100644 --- a/lib/pages/discount/discount_list_row.dart +++ b/lib/pages/discount/discount_list_row.dart @@ -5,6 +5,7 @@ import 'package:fcs/pages/discount/discount_editor.dart'; import 'package:fcs/pages/main/util.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_vector_icons/flutter_vector_icons.dart'; import 'package:intl/intl.dart'; typedef OnSelect(Discount discount); diff --git a/lib/pages/discount/model/discount_model.dart b/lib/pages/discount/model/discount_model.dart index 445853f..df50e03 100644 --- a/lib/pages/discount/model/discount_model.dart +++ b/lib/pages/discount/model/discount_model.dart @@ -30,9 +30,7 @@ class DiscountModel extends BaseModel { initData() { _selectedIndex = 1; _load(); - - if (_used != null) _used.close(); - if (_getUsed() != null) _used = _getUsed()!; + if (_getUsed() != null) _used = _getUsed(); _used.load(); } @@ -44,14 +42,14 @@ class DiscountModel extends BaseModel { _load() { if (listener != null) listener!.cancel(); try { - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("/$discounts_collection") .orderBy("code", descending: false) .snapshots() .listen((snaps) { _discounts.clear(); - snaps.documents.forEach((d) { - _discounts.add(Discount.fromMap(d.data, d.documentID)); + snaps.docs.forEach((d) { + _discounts.add(Discount.fromMap(d.data as Map, d.id)); }); notifyListeners(); }); @@ -60,10 +58,10 @@ class DiscountModel extends BaseModel { } } - Paginator? _getUsed() { - if (user == null || !user.hasFcsShipments()) return null; + Paginator _getUsed() { + if (user == null || !user!.hasFcsShipments()) throw "No Privilege"; - var pageQuery = Firestore.instance + var pageQuery = FirebaseFirestore.instance .collection("/$discounts_collection") .where("status", isEqualTo: fcs_shipment_shipped_status) .orderBy("code", descending: false); @@ -73,17 +71,17 @@ class DiscountModel extends BaseModel { return paginator; } - Future?> getDiscount(String userID) async { + Future?> getDiscount(String userID) async { String path = "/$discounts_collection"; try { - var q = Firestore.instance + var q = FirebaseFirestore.instance .collection("$path") .where("customer_id", isEqualTo: userID) .where("status", isEqualTo: "available"); - var snaps = await q.getDocuments(source: Source.server); - List discounts = snaps.documents.map((snap) { + var snaps = await q.get(const GetOptions(source: Source.server)); + var discounts = snaps.docs.map((snap) { if (snap.exists) { - var s = Discount.fromMap(snap.data, snap.documentID); + var s = Discount.fromMap(snap.data as Map, snap.id); return s; } }).toList(); @@ -128,6 +126,6 @@ class DiscountModel extends BaseModel { } Future deleteDiscount(Discount discount) async { - return Services.instance.commonService.deleteDiscount(discount.id); + return Services.instance.commonService.deleteDiscount(discount.id!); } } diff --git a/lib/pages/faq/faq_detail_page.dart b/lib/pages/faq/faq_detail_page.dart index 9e7ea4b..d2bd99c 100644 --- a/lib/pages/faq/faq_detail_page.dart +++ b/lib/pages/faq/faq_detail_page.dart @@ -28,7 +28,8 @@ class _FAQDetailPageState extends State { @override Widget build(BuildContext context) { - faq = context.select((FAQModel m) => m.getFAQ(widget.faq.id)); + if(widget.faq.id != null) + faq = context.select((FAQModel m) => m.getFAQ(widget.faq.id!)); if (faq == null) return Text("Deleted"); bool isEditable = context.select((MainModel m) => m.faqEditable()); diff --git a/lib/pages/faq/faq_edit_page.dart b/lib/pages/faq/faq_edit_page.dart index a3c8ad4..d56471c 100644 --- a/lib/pages/faq/faq_edit_page.dart +++ b/lib/pages/faq/faq_edit_page.dart @@ -10,6 +10,7 @@ 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_vector_icons/flutter_vector_icons.dart'; import 'package:provider/provider.dart'; const info = "Select additional page"; @@ -43,13 +44,13 @@ class _FAQEditorState extends State { if (widget.faq != null) { _faq = widget.faq!; _sn.text = _faq.sn.toString(); - _engQ.text = _faq.questionEng; - _mmQ.text = _faq.questionMm; - _engA.text = _faq.answerEng; - _mmA.text = _faq.answerMm; - _pageLabelEng.text = _faq.pageLinkLabelEng; - _pageLabelMm.text = _faq.pageLinkLabelMm; - _pageLink = _faq.pageLink; + _engQ.text = _faq.questionEng ?? ""; + _mmQ.text = _faq.questionMm ?? ''; + _engA.text = _faq.answerEng ?? ''; + _mmA.text = _faq.answerMm ?? ''; + _pageLabelEng.text = _faq.pageLinkLabelEng ?? ""; + _pageLabelMm.text = _faq.pageLinkLabelMm ?? ""; + _pageLink = _faq.pageLink ?? ''; } } diff --git a/lib/pages/faq/model/faq_model.dart b/lib/pages/faq/model/faq_model.dart index ece61b7..cc43d41 100644 --- a/lib/pages/faq/model/faq_model.dart +++ b/lib/pages/faq/model/faq_model.dart @@ -12,22 +12,22 @@ class FAQModel extends BaseModel { List faqs = []; FAQ getFAQ(String id) { - return faqs.firstWhere((e) => e.id == id, orElse: () => null); + return faqs.firstWhere((e) => e.id == id, orElse: () => FAQ()); } - StreamSubscription listener; + StreamSubscription? listener; FAQModel() { - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); try { - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("/faqs") .orderBy("sn", descending: false) .snapshots() .listen((snaps) { faqs.clear(); - snaps.documents.forEach((d) { - faqs.add(FAQ.fromMap(d.data, d.documentID)); + snaps.docs.forEach((d) { + faqs.add(FAQ.fromMap(d.data as Map, d.id)); }); notifyListeners(); }); diff --git a/lib/pages/faq/widgets.dart b/lib/pages/faq/widgets.dart index ba1c60a..a954882 100644 --- a/lib/pages/faq/widgets.dart +++ b/lib/pages/faq/widgets.dart @@ -7,14 +7,14 @@ Widget itemTitle(BuildContext context, String textKey) { return Padding( padding: const EdgeInsets.only(left: 18.0, top: 15, bottom: 0), child: Text( - AppTranslations.of(context).text(textKey), + AppTranslations.of(context)!.text(textKey), style: TextStyle( fontWeight: FontWeight.bold, fontSize: 18, color: Colors.black), ), ); } -Widget subItemTitle(BuildContext context, String textKey, {IconData iconData}) { +Widget subItemTitle(BuildContext context, String textKey, {IconData? iconData}) { return Padding( padding: const EdgeInsets.only(left: 0, top: 0, bottom: 0), child: Row( @@ -25,7 +25,7 @@ Widget subItemTitle(BuildContext context, String textKey, {IconData iconData}) { ), SizedBox(width: 10), Text( - AppTranslations.of(context).text(textKey), + AppTranslations.of(context)!.text(textKey), style: TextStyle( fontWeight: FontWeight.w700, fontSize: 15, color: primaryColor), ), @@ -35,7 +35,7 @@ Widget subItemTitle(BuildContext context, String textKey, {IconData iconData}) { } Widget contactItem(BuildContext context, String text, IconData iconData, - {Function() onTap, String labelKey}) { + {Function()? onTap, String? labelKey}) { return Material( child: Padding( padding: const EdgeInsets.only(left: 18.0, bottom: 10, right: 18), diff --git a/lib/pages/fcs_shipment/fcs_shipment_editor.dart b/lib/pages/fcs_shipment/fcs_shipment_editor.dart index 05bbc72..0a48598 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_editor.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_editor.dart @@ -49,19 +49,22 @@ class _FcsShipmentEditorState extends State { _isNew = widget.shipment == null; if (widget.shipment != null) { _shipment = widget.shipment!; - _shipmentNumberController.text = _shipment.shipmentNumber; - _cutoffDateController.text = dateFormatter.format(_shipment.cutoffDate); - _arrivalDateController.text = dateFormatter.format(_shipment.arrivalDate); + _shipmentNumberController.text = _shipment.shipmentNumber ?? ""; + if(_shipment.cutoffDate != null) + _cutoffDateController.text = dateFormatter.format(_shipment.cutoffDate!); + if(_shipment.arrivalDate != null) + _arrivalDateController.text = dateFormatter.format(_shipment.arrivalDate!); + if(_shipment.departureDate != null) _departureDateControler.text = - dateFormatter.format(_shipment.departureDate); - _statusController.text = _shipment.status; + dateFormatter.format(_shipment.departureDate!); + _statusController.text = _shipment.status ?? ""; _currentShipmentType = _shipment.shipType; - _consigneeController.text = _shipment.consignee; - _portController.text = _shipment.port; - _destinationController.text = _shipment.destination; + _consigneeController.text = _shipment.consignee ?? ""; + _portController.text = _shipment.port ?? ""; + _destinationController.text = _shipment.destination ?? ""; } else { var mainModel = Provider.of(context, listen: false); - _currentShipmentType = mainModel.setting.shipmentTypes[0]; + _currentShipmentType = mainModel.setting!.shipmentTypes[0]; } } @@ -143,10 +146,10 @@ class _FcsShipmentEditorState extends State { labelStyle: languageModel.isEng ? newLabelStyle(color: Colors.black54, fontSize: 20) : newLabelStyleMM(color: Colors.black54, fontSize: 20), - labelText: AppTranslations.of(context) + labelText: AppTranslations.of(context)! .text('FCSshipment.shipment_type'), icon: Icon(Ionicons.ios_airplane, color: primaryColor)), - items: mainModel.setting.shipmentTypes + items: mainModel.setting!.shipmentTypes .map((e) => DropdownMenuItem(child: Text(e), value: e)) .toList(), onChanged: (String? selected) => { @@ -285,7 +288,7 @@ class _FcsShipmentEditorState extends State { _consigneeController.text != "" || _portController.text != "" || _destinationController.text != "" || - _currentShipmentType != mainModel.setting.shipmentTypes[0]; + _currentShipmentType != mainModel.setting!.shipmentTypes[0]; } else { FcsShipment fcsShipment = _getPayload(); return widget.shipment!.isChangedForEdit(fcsShipment); diff --git a/lib/pages/fcs_shipment/fcs_shipment_info.dart b/lib/pages/fcs_shipment/fcs_shipment_info.dart index 3635571..ffd7723 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_info.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_info.dart @@ -48,17 +48,20 @@ class _FcsShipmentInfoState extends State { } _load() { - _shipmentNumberController.text = _fcsShipment!.shipmentNumber; - _cutoffDateController.text = dateFormatter.format(_fcsShipment!.cutoffDate); + _shipmentNumberController.text = _fcsShipment!.shipmentNumber ?? ""; + if(_fcsShipment!.cutoffDate != null) + _cutoffDateController.text = dateFormatter.format(_fcsShipment!.cutoffDate!); + if(_fcsShipment!.arrivalDate != null) _arrivalDateController.text = - dateFormatter.format(_fcsShipment!.arrivalDate); + dateFormatter.format(_fcsShipment!.arrivalDate!); + if(_fcsShipment!.departureDate != null) _departureDateControler.text = - dateFormatter.format(_fcsShipment!.departureDate); - _shipmentTypeControler.text = _fcsShipment!.shipType; - _consigneeController.text = _fcsShipment!.consignee; - _portController.text = _fcsShipment!.port; - _destinationController.text = _fcsShipment!.destination; - _statusController.text = _fcsShipment!.status; + dateFormatter.format(_fcsShipment!.departureDate!); + _shipmentTypeControler.text = _fcsShipment!.shipType ?? ""; + _consigneeController.text = _fcsShipment!.consignee ?? ""; + _portController.text = _fcsShipment!.port ?? ""; + _destinationController.text = _fcsShipment!.destination ?? ""; + _statusController.text = _fcsShipment!.status ?? ""; } @override @@ -182,6 +185,7 @@ class _FcsShipmentInfoState extends State { } _edit() async { + var f; bool? updated = await Navigator.push( context, CupertinoPageRoute( @@ -189,7 +193,8 @@ class _FcsShipmentInfoState extends State { ); if (updated ?? false) { var shipmentModel = Provider.of(context, listen: false); - var f = await shipmentModel.getFcsShipment(_fcsShipment!.id); + if(_fcsShipment != null && _fcsShipment!.id != null ) + f = await shipmentModel.getFcsShipment(_fcsShipment!.id!); setState(() { _fcsShipment = f; }); diff --git a/lib/pages/fcs_shipment/fcs_shipment_list_row.dart b/lib/pages/fcs_shipment/fcs_shipment_list_row.dart index 3a6da34..b16e410 100644 --- a/lib/pages/fcs_shipment/fcs_shipment_list_row.dart +++ b/lib/pages/fcs_shipment/fcs_shipment_list_row.dart @@ -43,9 +43,7 @@ class FcsShipmentListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 8.0), child: new Text( - shipment!.shipmentNumber == null - ? '' - : shipment!.shipmentNumber, + shipment?.shipmentNumber ?? '', style: new TextStyle( fontSize: 15.0, color: Colors.black), ), @@ -53,7 +51,7 @@ class FcsShipmentListRow extends StatelessWidget { Padding( padding: const EdgeInsets.only(left: 10.0, top: 10), child: new Text( - dateFormatter.format(shipment!.cutoffDate), + dateFormatter.format(shipment!.cutoffDate!), style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), @@ -67,7 +65,7 @@ class FcsShipmentListRow extends StatelessWidget { ), Padding( padding: const EdgeInsets.all(0), - child: getStatus(shipment!.status), + child: getStatus(shipment!.status ?? ''), ), ], ), diff --git a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart index aaf40a4..45d2141 100644 --- a/lib/pages/fcs_shipment/model/fcs_shipment_model.dart +++ b/lib/pages/fcs_shipment/model/fcs_shipment_model.dart @@ -11,13 +11,13 @@ import 'package:logging/logging.dart'; class FcsShipmentModel extends BaseModel { final log = Logger('FcsShipmentModel'); - StreamSubscription listener; + StreamSubscription? listener; List _fcsShipments = []; List get fcsShipments => _selectedIndex == 1 ? _fcsShipments : List.from(_shipped.values); - Paginator _shipped; + late Paginator _shipped; bool isLoading = false; int _selectedIndex = 1; set selectedIndex(int index) { @@ -25,7 +25,7 @@ class FcsShipmentModel extends BaseModel { notifyListeners(); } - get selectedIndex => _selectedIndex; + int get selectedIndex => _selectedIndex; @override void privilegeChanged() { @@ -43,12 +43,12 @@ class FcsShipmentModel extends BaseModel { } Future _loadFcsShipments() async { - if (user == null || !user.hasFcsShipments()) return; + if (user == null || !user!.hasFcsShipments()) throw "No Privilege"; String path = "/$fcs_shipment_collection/"; - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); _fcsShipments = []; try { - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("$path") .where("status", isEqualTo: fcs_shipment_confirmed_status) .where("is_deleted", isEqualTo: false) @@ -56,9 +56,9 @@ class FcsShipmentModel extends BaseModel { .snapshots() .listen((QuerySnapshot snapshot) { _fcsShipments.clear(); - _fcsShipments = snapshot.documents.map((documentSnapshot) { + _fcsShipments = snapshot.docs.map((documentSnapshot) { var s = FcsShipment.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return s; }).toList(); notifyListeners(); @@ -69,9 +69,9 @@ class FcsShipmentModel extends BaseModel { } Paginator _getShipped() { - if (user == null || !user.hasFcsShipments()) return null; + if (user == null || !user!.hasFcsShipments()) throw "No Privilege"; - var pageQuery = Firestore.instance + var pageQuery = FirebaseFirestore.instance .collection("/$fcs_shipment_collection") .where("status", isEqualTo: fcs_shipment_shipped_status) .where("is_deleted", isEqualTo: false) @@ -102,13 +102,13 @@ class FcsShipmentModel extends BaseModel { Future> getActiveFcsShipments() async { List fcsShipments = []; try { - var snaps = await Firestore.instance + var snaps = await FirebaseFirestore.instance .collection("/$fcs_shipment_collection") .where("status", isEqualTo: fcs_shipment_confirmed_status) - .getDocuments(source: Source.server); - fcsShipments = snaps.documents.map((documentSnapshot) { + .get(const GetOptions(source: Source.server)); + fcsShipments = snaps.docs.map((documentSnapshot) { var fcs = FcsShipment.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return fcs; }).toList(); } catch (e) { @@ -117,13 +117,13 @@ class FcsShipmentModel extends BaseModel { return fcsShipments; } - Future getFcsShipment(String id) async { + Future getFcsShipment(String id) async { try { - var snap = await Firestore.instance + var snap = await FirebaseFirestore.instance .collection("/$fcs_shipment_collection") - .document(id) - .get(source: Source.server); - var fcs = FcsShipment.fromMap(snap.data, snap.documentID); + .doc(id) + .get(const GetOptions(source: Source.server)); + var fcs = FcsShipment.fromMap(snap.data as Map, snap.id); return fcs; } catch (e) { @@ -135,13 +135,13 @@ class FcsShipmentModel extends BaseModel { Future> getInvoiceFcsShipments() async { List fcsShipments = []; try { - var snaps = await Firestore.instance + var snaps = await FirebaseFirestore.instance .collection("/$fcs_shipment_collection") .where("pending_invoice_user_count", isGreaterThan: 0) - .getDocuments(source: Source.server); - fcsShipments = snaps.documents.map((documentSnapshot) { + .get(const GetOptions(source: Source.server)); + fcsShipments = snaps.docs.map((documentSnapshot) { var fcs = FcsShipment.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return fcs; }).toList(); } catch (e) { @@ -156,7 +156,7 @@ class FcsShipmentModel extends BaseModel { @override logout() async { - if (listener != null) await listener.cancel(); + if (listener != null) await listener!.cancel(); if (_shipped != null) _shipped.close(); _fcsShipments = []; } diff --git a/lib/pages/invoice/editor/invoice_discount_list.dart b/lib/pages/invoice/editor/invoice_discount_list.dart index 3381a3e..a86a056 100644 --- a/lib/pages/invoice/editor/invoice_discount_list.dart +++ b/lib/pages/invoice/editor/invoice_discount_list.dart @@ -6,7 +6,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class InvoiceDiscountList extends StatelessWidget { - final List? discounts; + final List? discounts; const InvoiceDiscountList({ Key? key, @@ -68,14 +68,14 @@ class InvoiceDiscountList extends StatelessWidget { 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), style: textStyle), + Text(c?.amount.toStringAsFixed(2) ?? "", style: textStyle), ], ), ), diff --git a/lib/pages/invoice/editor/invoice_editor.dart b/lib/pages/invoice/editor/invoice_editor.dart index b40c834..c8b9efa 100644 --- a/lib/pages/invoice/editor/invoice_editor.dart +++ b/lib/pages/invoice/editor/invoice_editor.dart @@ -113,7 +113,7 @@ class _InvoiceEditorState extends State { }); } - List discounts = []; + List discounts = []; _loadDiscount() async { DiscountModel discountModel = Provider.of(context, listen: false); diff --git a/lib/pages/processing_old/processing_editor.dart b/lib/pages/processing_old/processing_editor.dart index 62fb147..59e0a3c 100644 --- a/lib/pages/processing_old/processing_editor.dart +++ b/lib/pages/processing_old/processing_editor.dart @@ -229,7 +229,7 @@ class _ProcessingEditorState extends State { } _completeProcessing() async { - if (_user.fcsID == null || _user.fcsID == "") { + if (_user!.fcsID == null || _user!.fcsID == "") { showMsgDialog(context, "Error", "Expected FCS-ID"); return; } @@ -239,11 +239,11 @@ class _ProcessingEditorState extends State { PackageModel packageModel = Provider.of(context, listen: false); try { - _package.fcsID = _user.fcsID; - _package.desc = _descCtl.text; - _package.remark = _remarkCtl.text; - _package.market = selectedMarket; - await packageModel.updateProcessing(_package, + _package!.fcsID = _user!.fcsID; + _package!.desc = _descCtl.text; + _package!.remark = _remarkCtl.text; + _package!.market = selectedMarket; + await packageModel.updateProcessing(_package!, multiImgController.getAddedFile, multiImgController.getDeletedUrl); Navigator.pop(context); } catch (e) { diff --git a/lib/pages/rates/custom_editor.dart b/lib/pages/rates/custom_editor.dart index bec5ddb..4e7f2b1 100644 --- a/lib/pages/rates/custom_editor.dart +++ b/lib/pages/rates/custom_editor.dart @@ -36,7 +36,7 @@ class _CustomEditorState extends State { _productController.text = _custom.name??""; _feeController.text = _custom.customDutyFee.toStringAsFixed(2); _shipmentRateController.text = - _custom.rate == null ? "" : _custom.rate.toStringAsFixed(2); + _custom.rate == null ? "" : _custom.rate?.toStringAsFixed(2) ?? ''; } else { _isNew = true; } diff --git a/lib/pages/rates/custom_list.dart b/lib/pages/rates/custom_list.dart index 5657815..898c8a3 100644 --- a/lib/pages/rates/custom_list.dart +++ b/lib/pages/rates/custom_list.dart @@ -85,7 +85,8 @@ class _CustomListState extends State { "Custom Fee \$ " + custom.customDutyFee.toStringAsFixed(2), custom.rate == null ? "" - : "Shipment rate \$ " + custom.rate.toStringAsFixed(2)), + : "Shipment rate \$ " + + custom.rate!.toStringAsFixed(2)), ), ); }), diff --git a/lib/pages/rates/shipment_rates_calculate.dart b/lib/pages/rates/shipment_rates_calculate.dart index c722c86..d956a55 100644 --- a/lib/pages/rates/shipment_rates_calculate.dart +++ b/lib/pages/rates/shipment_rates_calculate.dart @@ -62,11 +62,11 @@ class _ShipmentRatesCalState extends State { var amount = box.calAmount(rate); var shipmentWeight = box.getShipmentWeight(rate.volumetricRatio); var effectiveWeight = - _cargoType.weight > shipmentWeight ? _cargoType.weight : shipmentWeight; + _cargoType.weight! > shipmentWeight ? _cargoType.weight : shipmentWeight; setState(() { _deliveryFee = - effectiveWeight > rate.freeDeliveryWeight ? 0 : rate.deliveryFee; + effectiveWeight! > rate.freeDeliveryWeight ? 0 : rate.deliveryFee; _amount = amount == null ? 0 : amount + _deliveryFee; _shipmentWeight = shipmentWeight.toDouble(); }); diff --git a/lib/pages/staff/model/staff_model.dart b/lib/pages/staff/model/staff_model.dart index cadb5a4..b2c2ebb 100644 --- a/lib/pages/staff/model/staff_model.dart +++ b/lib/pages/staff/model/staff_model.dart @@ -11,8 +11,8 @@ import 'package:logging/logging.dart'; class StaffModel extends BaseModel { final log = Logger('StaffModel'); - StreamSubscription listener; - StreamSubscription privilegeListener; + StreamSubscription? listener; + StreamSubscription? privilegeListener; List employees = []; List privileges = []; @@ -26,28 +26,28 @@ class StaffModel extends BaseModel { @override logout() async { - if (listener != null) listener.cancel(); - if (privilegeListener != null) privilegeListener.cancel(); + if (listener != null) listener!.cancel(); + if (privilegeListener != null) privilegeListener!.cancel(); employees = []; privileges = []; } Future _loadEmployees() async { - if (user == null || !user.hasStaffs()) return; + if (user == null || !user!.hasStaffs()) throw "No Privilege"; try { - if (listener != null) listener.cancel(); + if (listener != null) listener!.cancel(); - listener = Firestore.instance + listener = FirebaseFirestore.instance .collection("/$user_collection") .where("is_employee", isEqualTo: true) .where("is_sys_admin", isEqualTo: false) .snapshots() .listen((QuerySnapshot snapshot) { employees.clear(); - employees = snapshot.documents.map((documentSnapshot) { + employees = snapshot.docs.map((documentSnapshot) { var user = - User.fromMap(documentSnapshot.data, documentSnapshot.documentID); + User.fromMap(documentSnapshot.data as Map, documentSnapshot.id); return user; }).toList(); notifyListeners(); @@ -59,14 +59,14 @@ class StaffModel extends BaseModel { Future _loadPrivileges() async { try { - privilegeListener = Firestore.instance + privilegeListener = FirebaseFirestore.instance .collection("/$privilege_collection") .snapshots() .listen((QuerySnapshot snapshot) { privileges.clear(); - privileges = snapshot.documents.map((documentSnapshot) { + privileges = snapshot.docs.map((documentSnapshot) { var privilege = Privilege.fromMap( - documentSnapshot.data, documentSnapshot.documentID); + documentSnapshot.data as Map, documentSnapshot.id); return privilege; }).toList(); notifyListeners(); @@ -82,27 +82,27 @@ class StaffModel extends BaseModel { token: await getToken()); } - Future findUser(String phoneNumber) { + Future findUser(String phoneNumber) { return Services.instance.userService.findUser(phoneNumber); } Future> getPickupEmployees() async { - if (user == null || !user.hasShipment()) return []; + if (user == null || !user!.hasShipment()) return []; return _getUsers(privilege_shipment); } Future> _getUsers(String privilege) async { List users = []; try { - var snaps = await Firestore.instance + var snaps = await FirebaseFirestore.instance .collection("/$user_collection") .where("is_employee", isEqualTo: true) .where("is_sys_admin", isEqualTo: false) .where("privileges", arrayContains: privilege) - .getDocuments(source: Source.server); - users = snaps.documents.map((documentSnapshot) { + .get(const GetOptions(source: Source.server)); + users = snaps.docs.map((documentSnapshot) { var user = - User.fromMap(documentSnapshot.data, documentSnapshot.documentID); + User.fromMap(documentSnapshot.data as Map, documentSnapshot.id); return user; }).toList(); } catch (e) { diff --git a/lib/pages/staff/staff_editor.dart b/lib/pages/staff/staff_editor.dart index 4812c32..67197e0 100644 --- a/lib/pages/staff/staff_editor.dart +++ b/lib/pages/staff/staff_editor.dart @@ -15,7 +15,7 @@ import 'package:provider/provider.dart'; typedef void FindCallBack(); class StaffEditor extends StatefulWidget { - final User staff; + final User? staff; const StaffEditor({this.staff}); @override _StaffEditorState createState() => _StaffEditorState(); @@ -25,8 +25,8 @@ class _StaffEditorState extends State { TextEditingController _phoneInput = new TextEditingController(); bool _isLoading = false; - User user; - User selectedUser; + late User user; + User? selectedUser; List privileges = []; bool isNew = true; @@ -38,8 +38,8 @@ class _StaffEditorState extends State { user = User(); if (!isNew) { user = - User(name: widget.staff.name, phoneNumber: widget.staff.phoneNumber); - user.privileges = widget.staff.privileges; + User(name: widget.staff!.name, phoneNumber: widget.staff!.phoneNumber); + user.privileges = widget.staff!.privileges; privileges.forEach((p) => user.privileges.contains(p.id) ? p.isChecked = true : p.isChecked = false); @@ -56,7 +56,7 @@ class _StaffEditorState extends State { title: InkWell( onTap: () { setState(() { - p.isChecked = p.isChecked == null ? true : !p.isChecked; + p.isChecked = p.isChecked == null ? true : !p.isChecked!; }); }, child: new Row( @@ -64,7 +64,8 @@ class _StaffEditorState extends State { new Checkbox( value: p.isChecked == null ? false : p.isChecked, activeColor: primaryColor, - onChanged: (bool value) { + onChanged: (bool? value) { + if(value != null) setState(() { p.isChecked = value; }); @@ -78,10 +79,10 @@ class _StaffEditorState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( - p.name, + p.name ??"", style: TextStyle(fontSize: 15.0, color: primaryColor), ), - Text(p.desc, + Text(p.desc ?? "", style: TextStyle(fontSize: 13, color: Colors.grey[600])) ], ), @@ -110,7 +111,7 @@ class _StaffEditorState extends State { style: textStyle, decoration: new InputDecoration( labelText: - AppTranslations.of(context).text('staff.phone.search'), + AppTranslations.of(context)!.text('staff.phone.search'), labelStyle: languageModel.isEng ? labelStyle : labelStyleMM, // icon: Icon( // Icons.search, @@ -150,7 +151,7 @@ class _StaffEditorState extends State { ? Container() : IconButton( icon: Icon(Icons.open_in_new, color: primaryColor), - onPressed: () => call(context, user.phoneNumber)), + onPressed: () => call(context, user.phoneNumber!)), ], ); @@ -226,7 +227,7 @@ class _StaffEditorState extends State { }); StaffModel staffModel = Provider.of(context, listen: false); try { - await staffModel.updatePrivileges(this.selectedUser.id, privilegesIDs()); + await staffModel.updatePrivileges(this.selectedUser!.id!, privilegesIDs()); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -238,7 +239,7 @@ class _StaffEditorState extends State { } List privilegesIDs() { - return this.privileges.where((p) => p.isChecked).map((p) => p.id).toList(); + return this.privileges.where((p) => p.isChecked!).map((p) => p.id).toList(); } _save() async { @@ -248,7 +249,7 @@ class _StaffEditorState extends State { if (widget.staff == null) return; StaffModel staffModel = Provider.of(context, listen: false); try { - await staffModel.updatePrivileges(widget.staff.id, privilegesIDs()); + await staffModel.updatePrivileges(widget.staff!.id!, privilegesIDs()); Navigator.pop(context); } catch (e) { showMsgDialog(context, "Error", e.toString()); @@ -267,7 +268,7 @@ class _StaffEditorState extends State { _isLoading = true; }); try { - User _user = await staffModel.findUser(_phoneInput.text); + User? _user = await staffModel.findUser(_phoneInput.text); if (_user == null) { showMsgDialog(context, "Error", _phoneInput.text + " not found!"); return; diff --git a/lib/pages/staff/staff_list.dart b/lib/pages/staff/staff_list.dart index fabcc6c..11fd119 100644 --- a/lib/pages/staff/staff_list.dart +++ b/lib/pages/staff/staff_list.dart @@ -5,7 +5,6 @@ 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:intl/intl.dart'; import 'package:provider/provider.dart'; @@ -84,7 +83,7 @@ class _StaffListState extends State { padding: new EdgeInsets.symmetric( horizontal: 32.0 - dotSize / 2), child: Icon( - MaterialCommunityIcons.worker, + Icons.person, color: primaryColor, size: 40, ), @@ -94,13 +93,13 @@ class _StaffListState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( - user.name, + user.name ?? "", style: new TextStyle(fontSize: 15.0), ), Padding( padding: const EdgeInsets.only(top: 8.0), child: new Text( - user.phoneNumber, + user.phoneNumber ?? "", style: new TextStyle( fontSize: 15.0, color: Colors.grey), ), diff --git a/lib/pages/user_search/user_serach.dart b/lib/pages/user_search/user_serach.dart index 6dc22e6..c61731c 100644 --- a/lib/pages/user_search/user_serach.dart +++ b/lib/pages/user_search/user_serach.dart @@ -17,7 +17,7 @@ Future searchUser(BuildContext context, ); class UserSearchDelegate extends SearchDelegate { - final OnUserSelect onUserSelect; + final OnUserSelect? onUserSelect; final bool popPage; UserSearchDelegate({required this.onUserSelect, required this.popPage}); @@ -119,7 +119,7 @@ class UserSearchDelegate extends SearchDelegate { _onUserRowSelect(BuildContext context, User user) { if (onUserSelect != null) { - onUserSelect(user); + onUserSelect!(user); } if (popPage) { Navigator.pop(context); diff --git a/lib/pages/widgets/local_popup_menu_button.dart b/lib/pages/widgets/local_popup_menu_button.dart index a73bb86..8fa1e62 100644 --- a/lib/pages/widgets/local_popup_menu_button.dart +++ b/lib/pages/widgets/local_popup_menu_button.dart @@ -78,7 +78,7 @@ class _LocalPopupMenuButtonState extends State { children: [ Icon( widget.buttonIcon ?? Icons.filter_list, - color: widget.buttonColor ?? primaryColor, + color: widget.buttonColor, ), hightlight ? Positioned( @@ -98,14 +98,12 @@ class _LocalPopupMenuButtonState extends State { )), itemBuilder: (BuildContext context) { return popmenus.map((LocalPopupMenu choice) { - if (choice == null) return null; return PopupMenuItem( value: choice, child: Row( children: [ - LocalText(context, choice.textKey, - color: - choice?.enabled ?? true ? primaryColor : Colors.grey), + LocalText(context, choice.textKey ?? "", + color: choice.enabled ? primaryColor : Colors.grey), SizedBox( width: 10, ), @@ -124,8 +122,8 @@ class _LocalPopupMenuButtonState extends State { bool _needHighlight() { popmenus.forEach((e) { - if (e == null) return false; - if (e.selected && e.highlight) return true; + if (e == null) return; + if (e.selected && e.highlight) return; }); return false; }