From c96c151f447fe5239e871bb35885cc54df9ccdbf Mon Sep 17 00:00:00 2001 From: Sultan khan <> Date: Thu, 9 Nov 2023 09:45:42 +0300 Subject: [PATCH] null safety issue fixed. --- lib/core/model/contactus/get_hmg_locations.dart | 2 +- lib/core/model/er/projectavgerwaitingtime.dart | 4 ++-- .../pharmacyModule/OrderPreviewViewModel.dart | 2 +- lib/pages/ErService/NearestEr.dart | 1 + lib/pages/ErService/OrderLogPage.dart | 6 +++--- lib/pages/landing/landing_page_pharmcy.dart | 2 +- .../screens/cart-page/cart-order-page.dart | 8 +++++--- .../screens/product-details/product-detail.dart | 4 ++-- lib/pages/pharmacy/profile/profile.dart | 7 ++++--- lib/widgets/hospital_location.dart | 17 +++++++++-------- lib/widgets/others/app_scaffold_widget.dart | 4 ++-- .../pharmacy/bottom_nav_pharmacy_item.dart | 2 +- 12 files changed, 32 insertions(+), 27 deletions(-) diff --git a/lib/core/model/contactus/get_hmg_locations.dart b/lib/core/model/contactus/get_hmg_locations.dart index fb2bdfe5..d15b8534 100644 --- a/lib/core/model/contactus/get_hmg_locations.dart +++ b/lib/core/model/contactus/get_hmg_locations.dart @@ -9,7 +9,7 @@ class GetHMGLocationsModel { String? locationName; dynamic locationNameN; dynamic locationType; - String? longitude; + String? longitude; int? pharmacyLocationID; String? phoneNumber; int? projectID; diff --git a/lib/core/model/er/projectavgerwaitingtime.dart b/lib/core/model/er/projectavgerwaitingtime.dart index ad78db43..ccc92a7e 100644 --- a/lib/core/model/er/projectavgerwaitingtime.dart +++ b/lib/core/model/er/projectavgerwaitingtime.dart @@ -30,7 +30,7 @@ class ProjectAvgERWaitingTime { distanceInKilometers = json['DistanceInKilometers']; latitude = json['Latitude']; longitude = json['Longitude']; - phonenumber = json['Phonenum?ber']; + phonenumber = json['PhoneNumber']; projectImageURL = json['ProjectImageURL']; projectName = json['ProjectName']; } @@ -44,7 +44,7 @@ class ProjectAvgERWaitingTime { data['DistanceInKilometers'] = this.distanceInKilometers; data['Latitude'] = this.latitude; data['Longitude'] = this.longitude; - data['Phonenum?ber'] = this.phonenumber; + data['PhoneNumber'] = this.phonenumber; data['ProjectImageURL'] = this.projectImageURL; data['ProjectName'] = this.projectName; return data; diff --git a/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart b/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart index 82abfbf0..cd8ae4a2 100644 --- a/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart +++ b/lib/core/viewModels/pharmacyModule/OrderPreviewViewModel.dart @@ -112,7 +112,7 @@ class OrderPreviewViewModel extends BaseViewModel { ShoppingCartResponse _handleGetShoppingCartResponse(Map res) { cartResponse.totalAmount = 0.0; totalAdditionalShippingCharge = 0; - if (res == null) { + if (res.isEmpty) { error = "response is null"; setState(ViewState.Error); return ShoppingCartResponse(); diff --git a/lib/pages/ErService/NearestEr.dart b/lib/pages/ErService/NearestEr.dart index 0a271b77..20b664d9 100644 --- a/lib/pages/ErService/NearestEr.dart +++ b/lib/pages/ErService/NearestEr.dart @@ -74,6 +74,7 @@ class _NearestErState extends State { location.locationName = projectAvgERWaitingTimeModelList[index].projectName; location.cityName = projectAvgERWaitingTimeModelList[index].projectName; location.projectImageURL = projectAvgERWaitingTimeModelList[index].projectImageURL; + print(projectAvgERWaitingTimeModelList[index].phonenumber); location.phoneNumber = projectAvgERWaitingTimeModelList[index].phonenumber; location.latitude = projectAvgERWaitingTimeModelList[index].latitude; location.longitude = projectAvgERWaitingTimeModelList[index].longitude; diff --git a/lib/pages/ErService/OrderLogPage.dart b/lib/pages/ErService/OrderLogPage.dart index d1995017..ff5066cf 100644 --- a/lib/pages/ErService/OrderLogPage.dart +++ b/lib/pages/ErService/OrderLogPage.dart @@ -227,7 +227,7 @@ class OrderLogPage extends StatelessWidget { 100, ), ), - Column( + Expanded(child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( @@ -236,10 +236,10 @@ class OrderLogPage extends StatelessWidget { ), Text( order.dropOffLocation!.trim().toString(), - style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.48), + style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.48), overflow: TextOverflow.ellipsis, ), ], - ), + )), ], ), ], diff --git a/lib/pages/landing/landing_page_pharmcy.dart b/lib/pages/landing/landing_page_pharmcy.dart index 61ee9af0..f31cfe41 100644 --- a/lib/pages/landing/landing_page_pharmcy.dart +++ b/lib/pages/landing/landing_page_pharmcy.dart @@ -76,7 +76,7 @@ class _LandingPagePharmacyState extends State { children: [ PharmacyPage(), PharmacyCategorisePage(), - PharmacyProfilePage(moveToOrder: false, changeTab: changeCurrentTab), + PharmacyProfilePage(moveToOrder: false, changeTab: (){changeCurrentTab(2);}), CartOrderPage(changeTab: changeCurrentTab), ], ), diff --git a/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart b/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart index d44cb426..98ff43e1 100644 --- a/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart +++ b/lib/pages/pharmacies/screens/cart-page/cart-order-page.dart @@ -22,7 +22,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class CartOrderPage extends StatefulWidget { - final dynamic? changeTab; + final void Function(int)? changeTab; CartOrderPage({Key? key, this.changeTab}) : super(key: key); @@ -57,8 +57,10 @@ class _CartOrderPageState extends State { isMainPharmacyPages: true, showPharmacyCart: false, baseViewModel: model, - backButtonTab: - widget.changeTab!, + backButtonTab:(){ + widget.changeTab!; + } + , backgroundColor: Colors.white, body: NetworkBaseView( diff --git a/lib/pages/pharmacies/screens/product-details/product-detail.dart b/lib/pages/pharmacies/screens/product-details/product-detail.dart index 794f051c..fa49cc51 100644 --- a/lib/pages/pharmacies/screens/product-details/product-detail.dart +++ b/lib/pages/pharmacies/screens/product-details/product-detail.dart @@ -132,13 +132,13 @@ class __ProductDetailPageState extends State { ), ), ), - if (model.isStockAvailable != null && !model.isStockAvailable) + if (model.isStockAvailable && !model.isStockAvailable) Container( height: MediaQuery.of(context).size.height * .40, color: Colors.white.withOpacity(0.6), // child: AppText("Out of Stock"), ), - if (model.isStockAvailable != null && !model.isStockAvailable) + if (model.isStockAvailable && !model.isStockAvailable) Positioned( // bottom: 10, top: MediaQuery.of(context).size.height * .088, diff --git a/lib/pages/pharmacy/profile/profile.dart b/lib/pages/pharmacy/profile/profile.dart index 5583a9ac..a844e0d2 100644 --- a/lib/pages/pharmacy/profile/profile.dart +++ b/lib/pages/pharmacy/profile/profile.dart @@ -30,7 +30,8 @@ dynamic languageID; class PharmacyProfilePage extends StatefulWidget { final bool moveToOrder; - final dynamic changeTab; + + final void Function()? changeTab; PharmacyProfilePage({required this.moveToOrder, this.changeTab}); @@ -55,8 +56,8 @@ class _ProfilePageState extends State { } getCustomer() async { - String custID; - String custGUID; + String? custID; + String? custGUID; custID = await sharedPref.getString(PHARMACY_CUSTOMER_ID); custGUID = await sharedPref.getObject(PHARMACY_CUSTOMER_GUID); setState(() { diff --git a/lib/widgets/hospital_location.dart b/lib/widgets/hospital_location.dart index 245bfaba..998f8250 100644 --- a/lib/widgets/hospital_location.dart +++ b/lib/widgets/hospital_location.dart @@ -10,7 +10,7 @@ import 'avatar/large_avatar.dart'; import 'my_rich_text.dart'; class HospitalLocation extends StatelessWidget { - final GetHMGLocationsModel location; + final GetHMGLocationsModel? location; final bool showCity; final String? waitingTime; @@ -41,7 +41,7 @@ class HospitalLocation extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - location.locationName!.trim(), + location!.locationName!.trim(), style: TextStyle(fontSize: 16, letterSpacing: -0.64, fontWeight: FontWeight.w600, color: Color(0xff2E303A)), ), SizedBox(height: 10), @@ -60,8 +60,8 @@ class HospitalLocation extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (showCity) MyRichText(TranslationBase.of(context).city + ":", location.cityName!.trim().toString(), projectViewModel.isArabic), - MyRichText(TranslationBase.of(context).distance + ":", location.distanceInKilometers.toString() + " " + TranslationBase.of(context).km_ ?? "", projectViewModel.isArabic), + if (showCity) MyRichText(TranslationBase.of(context).city + ":", location!.cityName!.trim().toString(), projectViewModel.isArabic), + MyRichText(TranslationBase.of(context).distance + ":", location!.distanceInKilometers.toString() + " " + TranslationBase.of(context).km_ ?? "", projectViewModel.isArabic), if (waitingTime != null) MyRichText(TranslationBase.of(context).waitingTime, waitingTime!, projectViewModel.isArabic), ], ), @@ -79,14 +79,15 @@ class HospitalLocation extends StatelessWidget { () async { await MapLauncher.showMarker( mapType: MapType.google, - coords: Coords(double.parse(location.latitude!), double.parse(location.longitude!)), - title: location.locationName!, + coords: Coords(double.parse(location!.latitude!), double.parse(location!.longitude!)), + title: location!.locationName!, ); }, ), SizedBox(height: 10), - contactButton(Icons.call, TranslationBase.of(context).callNow, () { - launchUrl(Uri.parse("tel://" + location.phoneNumber!)); + contactButton(Icons.call, TranslationBase.of(context).callNow, () async{ + + await launchUrl(Uri.parse("tel://" + location!.phoneNumber.toString())); }), ], ), diff --git a/lib/widgets/others/app_scaffold_widget.dart b/lib/widgets/others/app_scaffold_widget.dart index 21dea4fd..5d5ced79 100644 --- a/lib/widgets/others/app_scaffold_widget.dart +++ b/lib/widgets/others/app_scaffold_widget.dart @@ -285,7 +285,7 @@ class _AppScaffoldState extends State { bottomNavigationBar: widget.isBottomBar ? BottomNavPharmacyBar( changeIndex: changeCurrentTab, - index: widget.currentTab!, + index: widget.currentTab==null ? 0: widget.currentTab!, ) : null, floatingActionButton: widget.floatingActionButton, @@ -508,7 +508,7 @@ class AppBarWidgetState extends State { ? IconButton( icon: badge_import.Badge( badgeContent: Text( - orderPreviewViewModel.cartResponse.quantityCount.toString(), + orderPreviewViewModel.cartResponse.quantityCount !=null? orderPreviewViewModel.cartResponse.quantityCount.toString() :"", style: TextStyle(color: Colors.white), ), child: Icon(Icons.shopping_cart)), diff --git a/lib/widgets/pharmacy/bottom_nav_pharmacy_item.dart b/lib/widgets/pharmacy/bottom_nav_pharmacy_item.dart index 909f863d..819f29c3 100644 --- a/lib/widgets/pharmacy/bottom_nav_pharmacy_item.dart +++ b/lib/widgets/pharmacy/bottom_nav_pharmacy_item.dart @@ -87,7 +87,7 @@ class BottomNavPharmacyItem extends StatelessWidget { ), ), ), - if (currentIndex == 3 && Provider.of(context, listen: false).cartResponse.quantityCount != 0) + if (currentIndex == 3 && Provider.of(context, listen: false).cartResponse.quantityCount!=null && Provider.of(context, listen: false).cartResponse.quantityCount!=0) Positioned( top: 11.5, right: -3.5,