null safety

This commit is contained in:
Phaung Phaung
2021-09-10 15:23:13 +06:30
parent 5c5e47b9ad
commit 376153e22f
14 changed files with 80 additions and 66 deletions

View File

@@ -60,9 +60,8 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
if(widget.box != null) if (widget.box != null) _box = widget.box!;
_box = widget.box!; _selectedCartonType = _box.cartonType ?? '';
_selectedCartonType = _box.cartonType;
//for shipment weight //for shipment weight
volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false) volumetricRatio = Provider.of<ShipmentRateModel>(context, listen: false)
@@ -81,7 +80,7 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
_heightController.text = _box.height.toString(); _heightController.text = _box.height.toString();
_lengthController.text = _box.length.toString(); _lengthController.text = _box.length.toString();
_cargoTypes = _box.cargoTypes; _cargoTypes = _box.cargoTypes;
_deliveryAddress = _box.deliveryAddress; _deliveryAddress = _box.deliveryAddress!;
isMixBox = _box.cartonType == carton_mix_box; isMixBox = _box.cartonType == carton_mix_box;
isFromShipments = _box.cartonType == carton_from_shipments; isFromShipments = _box.cartonType == carton_from_shipments;
isFromPackages = _box.cartonType == carton_from_packages; isFromPackages = _box.cartonType == carton_from_packages;
@@ -97,7 +96,7 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
if (_box.cartonType == carton_from_packages && _box.userID == null) return; if (_box.cartonType == carton_from_packages && _box.userID == null) return;
PackageModel packageModel = PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false); Provider.of<PackageModel>(context, listen: false);
List<Package> packages = await packageModel.getPackages(_box.userID, [ List<Package> packages = await packageModel.getPackages(_box.userID!, [
package_processed_status, package_processed_status,
package_packed_status, package_packed_status,
package_shipped_status, package_shipped_status,
@@ -136,8 +135,9 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
final cartonTypeBox = LocalRadioButtons( final cartonTypeBox = LocalRadioButtons(
readOnly: true, readOnly: true,
values: cartonModel.cartonTypesInfo, values: cartonModel.cartonTypesInfo,
selectedValue: selectedValue: _box.isShipmentCarton ?? false
_box.isShipmentCarton ? carton_from_shipments : _box.cartonType); ? carton_from_shipments
: _box.cartonType);
final shipmentBox = DisplayText( final shipmentBox = DisplayText(
text: _box.fcsShipmentNumber, text: _box.fcsShipmentNumber,
labelTextKey: "box.fcs_shipment_num", labelTextKey: "box.fcs_shipment_num",
@@ -174,11 +174,11 @@ class _DeliveryInfoState extends State<DeliveryInfo> {
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: new Text( child: new Text(
_selectedShipmentBox.shipmentNumber, _selectedShipmentBox.shipmentNumber ?? "",
style: textStyle, style: textStyle,
)), )),
new Text( new Text(
_selectedShipmentBox.desc, _selectedShipmentBox.desc ?? "",
style: textStyle, style: textStyle,
), ),
], ],

View File

@@ -42,7 +42,7 @@ class DeliveryModel extends BaseModel {
if (listener != null) listener.cancel(); if (listener != null) listener.cancel();
_cartons = []; _cartons = [];
try { try {
listener = Firestore.instance listener = FirebaseFirestore.instance
.collection("$path") .collection("$path")
.where("status", isEqualTo: carton_shipped_status) .where("status", isEqualTo: carton_shipped_status)
.where("carton_type", whereIn: [ .where("carton_type", whereIn: [

View File

@@ -39,12 +39,12 @@ class _DeliveryAddressEditorState extends State<DeliveryAddressEditor> {
if (widget.deliveryAddress != null) { if (widget.deliveryAddress != null) {
_isNew = false; _isNew = false;
_deliveryAddress = widget.deliveryAddress!; _deliveryAddress = widget.deliveryAddress!;
_nameController.text = _deliveryAddress.fullName; _nameController.text = _deliveryAddress.fullName ?? "";
_address1Controller.text = _deliveryAddress.addressLine1; _address1Controller.text = _deliveryAddress.addressLine1 ?? "";
_address2Controller.text = _deliveryAddress.addressLine2; _address2Controller.text = _deliveryAddress.addressLine2 ?? "";
_cityController.text = _deliveryAddress.city; _cityController.text = _deliveryAddress.city ?? "";
_stateController.text = _deliveryAddress.state; _stateController.text = _deliveryAddress.state ?? "";
_phoneController.text = _deliveryAddress.phoneNumber; _phoneController.text = _deliveryAddress.phoneNumber?? "";
} else { } else {
_cityController.text = "Yangon"; _cityController.text = "Yangon";
_stateController.text = "Yangon"; _stateController.text = "Yangon";

View File

@@ -37,11 +37,11 @@ class _DiscountEditorState extends State<DiscountEditor> {
super.initState(); super.initState();
if (widget.discount != null) { if (widget.discount != null) {
_discount = widget.discount!; _discount = widget.discount!;
_codeController.text = _discount.code; _codeController.text = _discount.code ?? "";
_amountController.text = _discount.amount.toStringAsFixed(2); _amountController.text = _discount.amount.toStringAsFixed(2);
_statusController.text = _discount.status; _statusController.text = _discount.status ?? '';
customerName = _discount.customerName; customerName = _discount.customerName ?? "";
customerId = _discount.customerId; customerId = _discount.customerId ?? "";
} else { } else {
_isNew = true; _isNew = true;
} }
@@ -77,8 +77,8 @@ class _DiscountEditorState extends State<DiscountEditor> {
icon: Icon(Icons.search, color: primaryColor), icon: Icon(Icons.search, color: primaryColor),
onPressed: () => searchUser(context, onUserSelect: (u) { onPressed: () => searchUser(context, onUserSelect: (u) {
setState(() { setState(() {
customerId = u.id; customerId = u.id ?? "";
customerName = u.name; customerName = u.name ?? "";
}); });
},popPage: true)), },popPage: true)),
], ],

View File

@@ -28,7 +28,8 @@ class _FAQDetailPageState extends State<FAQDetailPage> {
@override @override
Widget build(BuildContext context) { 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"); if (faq == null) return Text("Deleted");
bool isEditable = context.select((MainModel m) => m.faqEditable()); bool isEditable = context.select((MainModel m) => m.faqEditable());

View File

@@ -44,13 +44,13 @@ class _FAQEditorState extends State<FAQEditor> {
if (widget.faq != null) { if (widget.faq != null) {
_faq = widget.faq!; _faq = widget.faq!;
_sn.text = _faq.sn.toString(); _sn.text = _faq.sn.toString();
_engQ.text = _faq.questionEng; _engQ.text = _faq.questionEng ?? "";
_mmQ.text = _faq.questionMm; _mmQ.text = _faq.questionMm ?? '';
_engA.text = _faq.answerEng; _engA.text = _faq.answerEng ?? '';
_mmA.text = _faq.answerMm; _mmA.text = _faq.answerMm ?? '';
_pageLabelEng.text = _faq.pageLinkLabelEng; _pageLabelEng.text = _faq.pageLinkLabelEng ?? "";
_pageLabelMm.text = _faq.pageLinkLabelMm; _pageLabelMm.text = _faq.pageLinkLabelMm ?? "";
_pageLink = _faq.pageLink; _pageLink = _faq.pageLink ?? '';
} }
} }

View File

@@ -49,16 +49,19 @@ class _FcsShipmentEditorState extends State<FcsShipmentEditor> {
_isNew = widget.shipment == null; _isNew = widget.shipment == null;
if (widget.shipment != null) { if (widget.shipment != null) {
_shipment = widget.shipment!; _shipment = widget.shipment!;
_shipmentNumberController.text = _shipment.shipmentNumber; _shipmentNumberController.text = _shipment.shipmentNumber ?? "";
_cutoffDateController.text = dateFormatter.format(_shipment.cutoffDate); if(_shipment.cutoffDate != null)
_arrivalDateController.text = dateFormatter.format(_shipment.arrivalDate); _cutoffDateController.text = dateFormatter.format(_shipment.cutoffDate!);
if(_shipment.arrivalDate != null)
_arrivalDateController.text = dateFormatter.format(_shipment.arrivalDate!);
if(_shipment.departureDate != null)
_departureDateControler.text = _departureDateControler.text =
dateFormatter.format(_shipment.departureDate); dateFormatter.format(_shipment.departureDate!);
_statusController.text = _shipment.status; _statusController.text = _shipment.status ?? "";
_currentShipmentType = _shipment.shipType; _currentShipmentType = _shipment.shipType;
_consigneeController.text = _shipment.consignee; _consigneeController.text = _shipment.consignee ?? "";
_portController.text = _shipment.port; _portController.text = _shipment.port ?? "";
_destinationController.text = _shipment.destination; _destinationController.text = _shipment.destination ?? "";
} else { } else {
var mainModel = Provider.of<MainModel>(context, listen: false); var mainModel = Provider.of<MainModel>(context, listen: false);
_currentShipmentType = mainModel.setting.shipmentTypes[0]; _currentShipmentType = mainModel.setting.shipmentTypes[0];

View File

@@ -48,17 +48,20 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
} }
_load() { _load() {
_shipmentNumberController.text = _fcsShipment!.shipmentNumber; _shipmentNumberController.text = _fcsShipment!.shipmentNumber ?? "";
_cutoffDateController.text = dateFormatter.format(_fcsShipment!.cutoffDate); if(_fcsShipment!.cutoffDate != null)
_cutoffDateController.text = dateFormatter.format(_fcsShipment!.cutoffDate!);
if(_fcsShipment!.arrivalDate != null)
_arrivalDateController.text = _arrivalDateController.text =
dateFormatter.format(_fcsShipment!.arrivalDate); dateFormatter.format(_fcsShipment!.arrivalDate!);
if(_fcsShipment!.departureDate != null)
_departureDateControler.text = _departureDateControler.text =
dateFormatter.format(_fcsShipment!.departureDate); dateFormatter.format(_fcsShipment!.departureDate!);
_shipmentTypeControler.text = _fcsShipment!.shipType; _shipmentTypeControler.text = _fcsShipment!.shipType ?? "";
_consigneeController.text = _fcsShipment!.consignee; _consigneeController.text = _fcsShipment!.consignee ?? "";
_portController.text = _fcsShipment!.port; _portController.text = _fcsShipment!.port ?? "";
_destinationController.text = _fcsShipment!.destination; _destinationController.text = _fcsShipment!.destination ?? "";
_statusController.text = _fcsShipment!.status; _statusController.text = _fcsShipment!.status ?? "";
} }
@override @override
@@ -182,6 +185,7 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
} }
_edit() async { _edit() async {
var f;
bool? updated = await Navigator.push<bool>( bool? updated = await Navigator.push<bool>(
context, context,
CupertinoPageRoute( CupertinoPageRoute(
@@ -189,7 +193,8 @@ class _FcsShipmentInfoState extends State<FcsShipmentInfo> {
); );
if (updated ?? false) { if (updated ?? false) {
var shipmentModel = Provider.of<FcsShipmentModel>(context, listen: false); var shipmentModel = Provider.of<FcsShipmentModel>(context, listen: false);
var f = await shipmentModel.getFcsShipment(_fcsShipment!.id); if(_fcsShipment != null && _fcsShipment!.id != null )
f = await shipmentModel.getFcsShipment(_fcsShipment!.id!);
setState(() { setState(() {
_fcsShipment = f; _fcsShipment = f;
}); });

View File

@@ -43,9 +43,7 @@ class FcsShipmentListRow extends StatelessWidget {
Padding( Padding(
padding: const EdgeInsets.only(left: 8.0), padding: const EdgeInsets.only(left: 8.0),
child: new Text( child: new Text(
shipment!.shipmentNumber == null shipment?.shipmentNumber ?? '',
? ''
: shipment!.shipmentNumber,
style: new TextStyle( style: new TextStyle(
fontSize: 15.0, color: Colors.black), fontSize: 15.0, color: Colors.black),
), ),
@@ -53,7 +51,7 @@ class FcsShipmentListRow extends StatelessWidget {
Padding( Padding(
padding: const EdgeInsets.only(left: 10.0, top: 10), padding: const EdgeInsets.only(left: 10.0, top: 10),
child: new Text( child: new Text(
dateFormatter.format(shipment!.cutoffDate), dateFormatter.format(shipment!.cutoffDate!),
style: new TextStyle( style: new TextStyle(
fontSize: 15.0, color: Colors.grey), fontSize: 15.0, color: Colors.grey),
), ),
@@ -67,7 +65,7 @@ class FcsShipmentListRow extends StatelessWidget {
), ),
Padding( Padding(
padding: const EdgeInsets.all(0), padding: const EdgeInsets.all(0),
child: getStatus(shipment!.status), child: getStatus(shipment!.status ?? ''),
), ),
], ],
), ),

View File

@@ -177,7 +177,7 @@ class _InitialLanguageSelectionPageState
setState(() { setState(() {
selectedIndex = index; selectedIndex = index;
selectedLanguage = lang; selectedLanguage = lang;
Translation().onLocaleChanged!(Locale(languagesMap[lang])); Translation().onLocaleChanged(Locale(languagesMap[lang]));
Provider.of<LanguageModel>(context, listen: false) Provider.of<LanguageModel>(context, listen: false)
.saveLanguage(selectedLanguage); .saveLanguage(selectedLanguage);
}); });

View File

@@ -56,7 +56,7 @@ class _StaffEditorState extends State<StaffEditor> {
title: InkWell( title: InkWell(
onTap: () { onTap: () {
setState(() { setState(() {
p.isChecked = p.isChecked == null ? true : !p.isChecked; p.isChecked = p.isChecked == null ? true : !p.isChecked!;
}); });
}, },
child: new Row( child: new Row(
@@ -79,10 +79,10 @@ class _StaffEditorState extends State<StaffEditor> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
new Text( new Text(
p.name, p.name ??"",
style: TextStyle(fontSize: 15.0, color: primaryColor), style: TextStyle(fontSize: 15.0, color: primaryColor),
), ),
Text(p.desc, Text(p.desc ?? "",
style: TextStyle(fontSize: 13, color: Colors.grey[600])) style: TextStyle(fontSize: 13, color: Colors.grey[600]))
], ],
), ),
@@ -151,7 +151,7 @@ class _StaffEditorState extends State<StaffEditor> {
? Container() ? Container()
: IconButton( : IconButton(
icon: Icon(Icons.open_in_new, color: primaryColor), icon: Icon(Icons.open_in_new, color: primaryColor),
onPressed: () => call(context, user.phoneNumber)), onPressed: () => call(context, user.phoneNumber!)),
], ],
); );
@@ -227,7 +227,7 @@ class _StaffEditorState extends State<StaffEditor> {
}); });
StaffModel staffModel = Provider.of<StaffModel>(context, listen: false); StaffModel staffModel = Provider.of<StaffModel>(context, listen: false);
try { try {
await staffModel.updatePrivileges(this.selectedUser!.id, privilegesIDs()); await staffModel.updatePrivileges(this.selectedUser!.id!, privilegesIDs());
Navigator.pop(context); Navigator.pop(context);
} catch (e) { } catch (e) {
showMsgDialog(context, "Error", e.toString()); showMsgDialog(context, "Error", e.toString());
@@ -239,7 +239,7 @@ class _StaffEditorState extends State<StaffEditor> {
} }
List<String> privilegesIDs() { List<String> 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 { _save() async {
@@ -249,7 +249,7 @@ class _StaffEditorState extends State<StaffEditor> {
if (widget.staff == null) return; if (widget.staff == null) return;
StaffModel staffModel = Provider.of<StaffModel>(context, listen: false); StaffModel staffModel = Provider.of<StaffModel>(context, listen: false);
try { try {
await staffModel.updatePrivileges(widget.staff!.id, privilegesIDs()); await staffModel.updatePrivileges(widget.staff!.id!, privilegesIDs());
Navigator.pop(context); Navigator.pop(context);
} catch (e) { } catch (e) {
showMsgDialog(context, "Error", e.toString()); showMsgDialog(context, "Error", e.toString());

View File

@@ -93,13 +93,13 @@ class _StaffListState extends State<StaffList> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
new Text( new Text(
user.name, user.name ?? "",
style: new TextStyle(fontSize: 15.0), style: new TextStyle(fontSize: 15.0),
), ),
Padding( Padding(
padding: const EdgeInsets.only(top: 8.0), padding: const EdgeInsets.only(top: 8.0),
child: new Text( child: new Text(
user.phoneNumber, user.phoneNumber ?? "",
style: new TextStyle( style: new TextStyle(
fontSize: 15.0, color: Colors.grey), fontSize: 15.0, color: Colors.grey),
), ),

View File

@@ -53,17 +53,17 @@ class _UserListRowState extends State<UserListRow> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
new Text( new Text(
user.name == null ? '' : user.name, user.name ?? "",
style: new TextStyle( style: new TextStyle(
fontSize: 15.0, color: Colors.black), fontSize: 15.0, color: Colors.black),
), ),
new Text( new Text(
user.fcsID == null ? "" : user.fcsID, user.fcsID ?? "",
style: new TextStyle( style: new TextStyle(
fontSize: 13.0, color: Colors.grey), fontSize: 13.0, color: Colors.grey),
), ),
new Text( new Text(
user.phoneNumber == null ? "" : user.phoneNumber, user.phoneNumber ?? "",
style: new TextStyle( style: new TextStyle(
fontSize: 13.0, color: Colors.grey), fontSize: 13.0, color: Colors.grey),
), ),

View File

@@ -349,6 +349,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.5.1" version: "1.5.1"
flutter_icons_null_safety:
dependency: "direct main"
description:
name: flutter_icons_null_safety
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
flutter_local_notifications: flutter_local_notifications:
dependency: "direct main" dependency: "direct main"
description: description: