filter api added

wala_plus
FaizHashmi 19 hours ago
parent 703f10349e
commit 74bb37593a

@ -1,6 +1,9 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:mohem_flutter_app/api/api_client.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/consts.dart';
@ -8,6 +11,7 @@ import 'package:mohem_flutter_app/models/offers_and_discounts/get_categories_lis
import 'package:mohem_flutter_app/models/offers_and_discounts/get_offers_list.dart';
import 'package:mohem_flutter_app/models/offers_and_discounts/wala_plus_category_model.dart';
import 'package:mohem_flutter_app/models/offers_and_discounts/wala_plus_retailer_model.dart';
import 'package:mohem_flutter_app/widgets/location/Location.dart' as location;
class OffersAndDiscountsApiClient {
static final OffersAndDiscountsApiClient _instance = OffersAndDiscountsApiClient._internal();
@ -75,13 +79,48 @@ class OffersAndDiscountsApiClient {
String _resolveUserName() {
String? pUserName = AppState().getUserName;
if (pUserName == null || pUserName.isEmpty) {
pUserName = AppState().postParamsObject?.userName ??
AppState().postParamsObject?.pUserName ??
AppState().memberInformationList?.eMPLOYEENUMBER;
pUserName = AppState().postParamsObject?.userName ?? AppState().postParamsObject?.pUserName ?? AppState().memberInformationList?.eMPLOYEENUMBER;
}
return pUserName ?? "";
}
// Same Location.isEnabled -> Location.havePermission -> Location.getCurrentLocation pattern
// used by mark_attendance_widget.dart (e.g. Wifi attendance), wrapped as a Future since this
// is a background enrichment of the request, not a blocking user action - any failure (service
// disabled, permission denied, error) just resolves to null so the retailer fetch still proceeds
// without WP_Geo_Location rather than showing permission dialogs here.
Future<Position?> _getCurrentPositionSilently(BuildContext context) async {
Completer<bool> enabledCompleter = Completer<bool>();
location.Location.isEnabled((bool isEnabled) {
if (!enabledCompleter.isCompleted) enabledCompleter.complete(isEnabled);
});
bool isEnabled = await enabledCompleter.future;
debugPrint("_getCurrentPositionSilently: location service isEnabled=$isEnabled");
if (!isEnabled) return null;
Completer<bool> permissionCompleter = Completer<bool>();
location.Location.havePermission((bool hasPermission) {
if (!permissionCompleter.isCompleted) permissionCompleter.complete(hasPermission);
});
bool hasPermission = await permissionCompleter.future;
debugPrint("_getCurrentPositionSilently: havePermission=$hasPermission");
if (!hasPermission) return null;
Completer<Position?> positionCompleter = Completer<Position?>();
location.Location.getCurrentLocation(
(Position position, bool isMocked) {
debugPrint("_getCurrentPositionSilently: got position lat=${position.latitude}, lng=${position.longitude}, isMocked=$isMocked");
if (!positionCompleter.isCompleted) positionCompleter.complete(position);
},
() {
debugPrint("_getCurrentPositionSilently: getCurrentLocation error callback fired");
if (!positionCompleter.isCompleted) positionCompleter.complete(null);
},
context,
);
return positionCompleter.future;
}
String _resolveDepNationalId() {
if (!ApiConsts.isDependetLogin) {
return "";
@ -116,7 +155,6 @@ class OffersAndDiscountsApiClient {
return "";
}
Map<String, dynamic> _getBaseWalaPlusParams() {
Map<String, dynamic> base = {};
base.addAll(AppState().postParamsJson);
@ -164,10 +202,7 @@ class OffersAndDiscountsApiClient {
(response) {
List<WalaPlusCategoryModel> categories = [];
if (response != null) {
dynamic cats = response['WalaPlus_Categories'] ??
response['walaPlus_Categories'] ??
response['WalaPlusCategories'] ??
response['result'];
dynamic cats = response['WalaPlus_Categories'] ?? response['walaPlus_Categories'] ?? response['WalaPlusCategories'] ?? response['result'];
if (cats is String) {
try {
cats = json.decode(cats);
@ -192,11 +227,30 @@ class OffersAndDiscountsApiClient {
);
}
// Confirmed with backend team: WP_Offer_Type accepts "online" and "store".
static const String walaPlusOfferTypeOnline = "online";
static const String walaPlusOfferTypeInStore = "store";
// Maps the screen's internal filter key ("online"/"instore"/"all") to the WP_Offer_Type value
// the backend expects. Returns null for "all" (or anything unrecognized) so callers can skip
// sending WP_Offer_Type entirely.
static String? mapOfferTypeFilter(String internalKey) {
switch (internalKey) {
case "online":
return walaPlusOfferTypeOnline;
case "instore":
return walaPlusOfferTypeInStore;
default:
return null;
}
}
Future<WalaPlusRetailersResponse?> getWalaPlusRetailers({
String? categoryId,
int page = 1,
int perPage = 10,
String? geoLocation,
String? offerType,
BuildContext? context,
String? mobileNumber,
}) async {
@ -216,6 +270,9 @@ class OffersAndDiscountsApiClient {
postParams["MemberType"] = ApiConsts.isDependetLogin ? 2 : 1;
postParams["CompanyID"] = 1;
postParams["WP_CategoryID"] = effectiveCatId;
if (offerType != null && offerType.trim().isNotEmpty) {
postParams["WP_Offer_Type"] = offerType.trim();
}
postParams["WP_Page"] = page;
postParams["WP_Per_page"] = perPage;
@ -227,11 +284,7 @@ class OffersAndDiscountsApiClient {
return await ApiClient().postJsonForObject(
(response) {
if (response != null) {
dynamic val = response['WalaPlus_Retailers'] ??
response['walaPlus_Retailers'] ??
response['WalaPlusRetailers'] ??
response['WP_Retailers'] ??
response['result'];
dynamic val = response['WalaPlus_Retailers'] ?? response['walaPlus_Retailers'] ?? response['WalaPlusRetailers'] ?? response['WP_Retailers'] ?? response['result'];
if (val is String) {
try {
val = json.decode(val);
@ -262,11 +315,7 @@ class OffersAndDiscountsApiClient {
);
}
Future<WalaPlusRetailerModel?> getWalaPlusRetailerById({
required String retailerId,
BuildContext? context,
String? mobileNumber,
}) async {
Future<WalaPlusRetailerModel?> getWalaPlusRetailerById({required String retailerId, BuildContext? context, String? mobileNumber}) async {
String url = ApiConsts.walaPlusRetailersByID;
String pUserName = _resolveUserName();
String pMobileNumber = _resolveMobileNumber(overrideMobile: mobileNumber);
@ -283,6 +332,20 @@ class OffersAndDiscountsApiClient {
}
postParams["MemberType"] = ApiConsts.isDependetLogin ? 2 : 1;
postParams["CompanyID"] = 1;
if (context != null) {
try {
Position? position = await _getCurrentPositionSilently(context);
log("context position: $position");
if (position != null) {
postParams["WP_Geo_Location"] = "${position.latitude},${position.longitude}";
}
} catch (e) {
debugPrint("getWalaPlusRetailerById: unable to get current location: $e");
}
}
_cleanWalaPlusParams(postParams);
debugPrint("getWalaPlusRetailerById: calling $url with WP_RetailerID: $retailerId");
@ -291,11 +354,7 @@ class OffersAndDiscountsApiClient {
(response) {
if (response != null) {
debugPrint("getWalaPlusRetailerById response keys: ${response is Map ? response.keys.toList() : 'non-map'}");
dynamic val = response['WalaPlus_RetailersByID'] ??
response['walaPlus_RetailersByID'] ??
response['WalaPlusRetailersByID'] ??
response['WP_RetailersByID'] ??
response['result'];
dynamic val = response['WalaPlus_RetailersByID'] ?? response['walaPlus_RetailersByID'] ?? response['WalaPlusRetailersByID'] ?? response['WP_RetailersByID'] ?? response['result'];
if (val is String) {
try {
val = json.decode(val);
@ -324,9 +383,7 @@ class OffersAndDiscountsApiClient {
}
if ((model?.locations == null || model!.locations!.isEmpty) &&
(map.containsKey('locations') || map.containsKey('Locations') || map.containsKey('location') || map.containsKey('Location'))) {
model?.locations = WalaPlusRetailerModel.parseLocationsList(
map['locations'] ?? map['Locations'] ?? map['location'] ?? map['Location'],
);
model?.locations = WalaPlusRetailerModel.parseLocationsList(map['locations'] ?? map['Locations'] ?? map['location'] ?? map['Location']);
}
} else if (response is Map<String, dynamic> && response.containsKey('name')) {
model = WalaPlusRetailerModel.fromJson(response);
@ -339,9 +396,7 @@ class OffersAndDiscountsApiClient {
}
if ((model.locations == null || model.locations!.isEmpty) &&
(response.containsKey('locations') || response.containsKey('Locations') || response.containsKey('location') || response.containsKey('Location'))) {
model.locations = WalaPlusRetailerModel.parseLocationsList(
response['locations'] ?? response['Locations'] ?? response['location'] ?? response['Location'],
);
model.locations = WalaPlusRetailerModel.parseLocationsList(response['locations'] ?? response['Locations'] ?? response['location'] ?? response['Location']);
}
}
debugPrint("getWalaPlusRetailerById: parsed retailer '${model.name}', offers: ${model.offers?.length ?? 0}, locations: ${model.locations?.length ?? 0}");
@ -370,12 +425,7 @@ class OffersAndDiscountsApiClient {
return "";
}
Future<Map<String, dynamic>?> redeemWalaPlusOffer({
required String offerId,
String? offerType,
String? userReference,
BuildContext? context,
}) async {
Future<Map<String, dynamic>?> redeemWalaPlusOffer({required String offerId, String? offerType, String? userReference, BuildContext? context}) async {
String url = ApiConsts.walaPlusOfferRedeem;
String pUserName = _resolveUserName();
String pUserReference = _resolveUserReference(overrideUserReference: userReference);
@ -405,10 +455,7 @@ class OffersAndDiscountsApiClient {
(response) {
if (response != null) {
debugPrint("redeemWalaPlusOffer response: $response");
dynamic val = response['WalaPlus_OfferRedeem'] ??
response['walaPlus_OfferRedeem'] ??
response['WalaPlusOfferRedeem'] ??
response['result'];
dynamic val = response['WalaPlus_OfferRedeem'] ?? response['walaPlus_OfferRedeem'] ?? response['WalaPlusOfferRedeem'] ?? response['result'];
if (val is String) {
try {
val = json.decode(val);

@ -9,12 +9,7 @@ class WalaPlusRetailersResponse {
int? perPage;
List<WalaPlusRetailerModel>? retailers;
WalaPlusRetailersResponse({
this.page,
this.pagesCount,
this.perPage,
this.retailers,
});
WalaPlusRetailersResponse({this.page, this.pagesCount, this.perPage, this.retailers});
factory WalaPlusRetailersResponse.fromJson(Map<String, dynamic> json) {
List<WalaPlusRetailerModel> retailersList = [];
@ -35,21 +30,15 @@ class WalaPlusRetailersResponse {
}
return WalaPlusRetailersResponse(
page: json['page'] is int
? json['page']
: int.tryParse(json['page']?.toString() ?? json['WP_Page']?.toString() ?? '1'),
pagesCount: json['pages_count'] is int
? json['pages_count']
: int.tryParse(json['pages_count']?.toString() ?? json['pagesCount']?.toString() ?? json['totalPages']?.toString() ?? '1'),
perPage: json['per_page'] is int
? json['per_page']
: int.tryParse(json['per_page']?.toString() ?? json['perPage']?.toString() ?? json['WP_Per_page']?.toString() ?? '10'),
page: json['page'] is int ? json['page'] : int.tryParse(json['page']?.toString() ?? json['WP_Page']?.toString() ?? '1'),
pagesCount: json['pages_count'] is int ? json['pages_count'] : int.tryParse(json['pages_count']?.toString() ?? json['pagesCount']?.toString() ?? json['totalPages']?.toString() ?? '1'),
perPage: json['per_page'] is int ? json['per_page'] : int.tryParse(json['per_page']?.toString() ?? json['perPage']?.toString() ?? json['WP_Per_page']?.toString() ?? '10'),
retailers: retailersList,
);
}
Map<String, dynamic> toJson() {
Map<String, dynamic> data = <String, dynamic>{};
Map<String, dynamic> data = <String, dynamic>{};
data['page'] = page;
data['pages_count'] = pagesCount;
data['per_page'] = perPage;
@ -68,22 +57,11 @@ class WalaPlusRetailersByIDResponse {
List<WalaPlusOfferModel>? offers;
List<WalaPlusRetailerModel>? retailer;
WalaPlusRetailersByIDResponse({
this.page,
this.pagesCount,
this.perPage,
this.locations,
this.offers,
this.retailer,
});
WalaPlusRetailersByIDResponse({this.page, this.pagesCount, this.perPage, this.locations, this.offers, this.retailer});
factory WalaPlusRetailersByIDResponse.fromJson(Map<String, dynamic> json) {
List<WalaPlusRetailerLocation> locList = WalaPlusRetailerModel.parseLocationsList(
json['locations'] ?? json['Locations'] ?? json['location'] ?? json['Location'],
);
List<WalaPlusOfferModel> offList = WalaPlusRetailerModel.parseOffersList(
json['offers'] ?? json['Offers'],
);
List<WalaPlusRetailerLocation> locList = WalaPlusRetailerModel.parseLocationsList(json['locations'] ?? json['Locations'] ?? json['location'] ?? json['Location']);
List<WalaPlusOfferModel> offList = WalaPlusRetailerModel.parseOffersList(json['offers'] ?? json['Offers']);
List<WalaPlusRetailerModel> retList = [];
dynamic retData = json['retailer'] ?? json['Retailer'];
@ -109,15 +87,9 @@ class WalaPlusRetailersByIDResponse {
}
return WalaPlusRetailersByIDResponse(
page: json['page'] is int
? json['page']
: int.tryParse(json['page']?.toString() ?? json['WP_Page']?.toString() ?? ''),
pagesCount: json['pages_count'] is int
? json['pages_count']
: int.tryParse(json['pages_count']?.toString() ?? json['pagesCount']?.toString() ?? ''),
perPage: json['per_page'] is int
? json['per_page']
: int.tryParse(json['per_page']?.toString() ?? json['perPage']?.toString() ?? ''),
page: json['page'] is int ? json['page'] : int.tryParse(json['page']?.toString() ?? json['WP_Page']?.toString() ?? ''),
pagesCount: json['pages_count'] is int ? json['pages_count'] : int.tryParse(json['pages_count']?.toString() ?? json['pagesCount']?.toString() ?? ''),
perPage: json['per_page'] is int ? json['per_page'] : int.tryParse(json['per_page']?.toString() ?? json['perPage']?.toString() ?? ''),
locations: locList,
offers: offList,
retailer: retList,
@ -289,9 +261,7 @@ class WalaPlusRetailerModel {
}
List<WalaPlusOfferModel> offersList = parseOffersList(offersSource ?? targetJson['offers'] ?? targetJson['Offers']);
List<WalaPlusRetailerLocation> locationsList = parseLocationsList(
locationsSource ?? targetJson['locations'] ?? targetJson['Locations'] ?? targetJson['location'] ?? targetJson['Location'],
);
List<WalaPlusRetailerLocation> locationsList = parseLocationsList(locationsSource ?? targetJson['locations'] ?? targetJson['Locations'] ?? targetJson['location'] ?? targetJson['Location']);
List<WalaPlusCategoryModel> categoriesList = [];
if (targetJson['categories'] != null && targetJson['categories'] is List) {
@ -309,7 +279,8 @@ class WalaPlusRetailerModel {
}
}
String? foundValidity = targetJson['validity']?.toString() ??
String? foundValidity =
targetJson['validity']?.toString() ??
targetJson['valid_to']?.toString() ??
targetJson['valid_until']?.toString() ??
targetJson['end_date']?.toString() ??
@ -323,9 +294,7 @@ class WalaPlusRetailerModel {
if (foundValidity == null || foundValidity == "null" || foundValidity.trim().isEmpty) {
for (var entry in targetJson.entries) {
String k = entry.key.toLowerCase();
if ((k.contains('valid') || k.contains('expir') || k.contains('duration')) &&
!k.contains('isverificationcodevalid') &&
!k.contains('barcode')) {
if ((k.contains('valid') || k.contains('expir') || k.contains('duration')) && !k.contains('isverificationcodevalid') && !k.contains('barcode')) {
if (entry.value != null && entry.value.toString().trim().isNotEmpty && entry.value.toString() != "null") {
foundValidity = entry.value.toString().trim();
break;
@ -335,7 +304,8 @@ class WalaPlusRetailerModel {
}
return WalaPlusRetailerModel(
id: targetJson['id']?.toString() ??
id:
targetJson['id']?.toString() ??
targetJson['WP_RetailerID']?.toString() ??
targetJson['retailer_id']?.toString() ??
targetJson['RetailerID']?.toString() ??
@ -388,10 +358,7 @@ class WalaPlusRetailerModel {
}
}
s = s
.replaceAll(r'\/', '/')
.replaceAll(r'\"', '"')
.replaceAll(r"\'", "'");
s = s.replaceAll(r'\/', '/').replaceAll(r'\"', '"').replaceAll(r"\'", "'");
s = s.replaceAllMapped(RegExp(r'\\u([0-9a-fA-F]{4})'), (match) {
try {
@ -600,10 +567,7 @@ class WalaPlusRetailerModel {
}
if (locations != null && locations!.isNotEmpty) {
for (var loc in locations!) {
if (loc.contact != null &&
loc.contact!.trim().isNotEmpty &&
loc.contact != "null" &&
!loc.contact!.contains('@')) {
if (loc.contact != null && loc.contact!.trim().isNotEmpty && loc.contact != "null" && !loc.contact!.contains('@')) {
return loc.contact!.trim();
}
}
@ -619,11 +583,12 @@ class WalaPlusRetailerModel {
bool get isOnlineStore => (type?.trim().toLowerCase() == 'online');
bool get isInstore => (type?.trim().toLowerCase() == 'instore' ||
type?.trim().toLowerCase() == 'in_store' ||
type?.trim().toLowerCase() == 'in store' ||
type?.trim().toLowerCase() == 'store' ||
(type == null && locations != null && locations!.isNotEmpty));
bool get isInstore =>
(type?.trim().toLowerCase() == 'instore' ||
type?.trim().toLowerCase() == 'in_store' ||
type?.trim().toLowerCase() == 'in store' ||
type?.trim().toLowerCase() == 'store' ||
(type == null && locations != null && locations!.isNotEmpty));
String? get normalizedType {
if (type != null && type!.trim().isNotEmpty) {
@ -659,16 +624,7 @@ class WalaPlusRetailerContact {
String? instagram;
String? twitter;
WalaPlusRetailerContact({
this.email,
this.emails,
this.phone,
this.phones,
this.website,
this.address,
this.instagram,
this.twitter,
});
WalaPlusRetailerContact({this.email, this.emails, this.phone, this.phones, this.website, this.address, this.instagram, this.twitter});
factory WalaPlusRetailerContact.fromJson(Map<String, dynamic> json) {
List<String> emailsList = [];
@ -706,16 +662,7 @@ class WalaPlusRetailerContact {
}
Map<String, dynamic> toJson() {
return {
'email': email,
'emails': emails,
'phone': phone,
'phones': phones,
'website': website,
'address': address,
'instagram': instagram,
'twitter': twitter,
};
return {'email': email, 'emails': emails, 'phone': phone, 'phones': phones, 'website': website, 'address': address, 'instagram': instagram, 'twitter': twitter};
}
String? get primaryEmail {
@ -748,6 +695,7 @@ class WalaPlusRetailerLocation {
String? contact;
String? countryNameAr;
String? countryNameEn;
String? distance;
double? latitude;
double? longitude;
dynamic placeId;
@ -761,6 +709,7 @@ class WalaPlusRetailerLocation {
this.contact,
this.countryNameAr,
this.countryNameEn,
this.distance,
this.latitude,
this.longitude,
this.placeId,
@ -776,6 +725,7 @@ class WalaPlusRetailerLocation {
contact: json['contact']?.toString(),
countryNameAr: WalaPlusRetailerModel.decodeUnicodeString(json['country_name_ar']),
countryNameEn: WalaPlusRetailerModel.decodeUnicodeString(json['country_name_en']),
distance: WalaPlusRetailerModel.decodeUnicodeString(json['distance']),
latitude: json['latitude'] is num ? (json['latitude'] as num).toDouble() : double.tryParse(json['latitude']?.toString() ?? ''),
longitude: json['longitude'] is num ? (json['longitude'] as num).toDouble() : double.tryParse(json['longitude']?.toString() ?? ''),
placeId: json['place_id'],
@ -792,6 +742,7 @@ class WalaPlusRetailerLocation {
data['contact'] = contact;
data['country_name_ar'] = countryNameAr;
data['country_name_en'] = countryNameEn;
data['distance'] = distance;
data['latitude'] = latitude;
data['longitude'] = longitude;
data['place_id'] = placeId;
@ -840,18 +791,7 @@ class WalaPlusOfferModel {
dynamic usage;
String? expiredAt;
WalaPlusOfferModel({
this.id,
this.retailerId,
this.title,
this.image,
this.imageThumb,
this.type,
this.description,
this.price,
this.usage,
this.expiredAt,
});
WalaPlusOfferModel({this.id, this.retailerId, this.title, this.image, this.imageThumb, this.type, this.description, this.price, this.usage, this.expiredAt});
factory WalaPlusOfferModel.fromJson(Map<String, dynamic> json) {
return WalaPlusOfferModel(

@ -240,12 +240,14 @@ class _DashboardScreenForDependetState extends State<DashboardScreenForDependet>
try {
String catParam = (targetCategoryId == "all" || targetCategoryId == "0") ? "" : targetCategoryId;
print("Fetching WalaPlus retailers: category='$catParam', page=1, per_page=$pageSize");
String? offerTypeParam = OffersAndDiscountsApiClient.mapOfferTypeFilter(selectedTypeFilter);
print("Fetching WalaPlus retailers: category='$catParam', offerType='$offerTypeParam', page=1, per_page=$pageSize");
WalaPlusRetailersResponse? response = await OffersAndDiscountsApiClient().getWalaPlusRetailers(
categoryId: catParam,
page: 1,
perPage: pageSize,
geoLocation: isNearestOffers ? "24.9485,46.977" : null,
offerType: offerTypeParam,
context: context,
);
@ -279,14 +281,16 @@ class _DashboardScreenForDependetState extends State<DashboardScreenForDependet>
try {
int nextPage = currentPage + 1;
String catParam = (currentCategoryId == "all" || currentCategoryId == "0") ? "" : currentCategoryId;
String? offerTypeParam = OffersAndDiscountsApiClient.mapOfferTypeFilter(selectedTypeFilter);
print("Fetching WalaPlus retailers next page: $nextPage of $totalPages, category: '$catParam'");
print("Fetching WalaPlus retailers next page: $nextPage of $totalPages, category: '$catParam', offerType: '$offerTypeParam'");
WalaPlusRetailersResponse? response = await OffersAndDiscountsApiClient().getWalaPlusRetailers(
categoryId: catParam,
page: nextPage,
perPage: pageSize,
geoLocation: isNearestOffers ? "24.9485,46.977" : null,
offerType: offerTypeParam,
context: context,
);
@ -320,22 +324,10 @@ class _DashboardScreenForDependetState extends State<DashboardScreenForDependet>
if (query != null) {
searchQuery = query;
}
// Type filtering (online/in store) is done server-side via WP_Offer_Type (see fetchOffers),
// so retailersList already reflects the selected type - only search is applied locally here.
List<WalaPlusRetailerModel> temp = retailersList;
if (selectedTypeFilter != "all" && selectedTypeFilter.isNotEmpty) {
temp =
temp.where((WalaPlusRetailerModel item) {
String? norm = item.normalizedType;
if (selectedTypeFilter == "online") {
return norm == "online";
} else if (selectedTypeFilter == "instore") {
return norm == "instore";
} else {
return norm == selectedTypeFilter || (item.type?.trim().toLowerCase() == selectedTypeFilter);
}
}).toList();
}
if (searchQuery.trim().isNotEmpty) {
String q = searchQuery.trim().toLowerCase();
temp =
@ -604,7 +596,7 @@ class _DashboardScreenForDependetState extends State<DashboardScreenForDependet>
setState(() {
selectedTypeFilter = typeKey;
});
_runFilter();
fetchOffers(categoryId: currentCategoryId.isEmpty ? "all" : currentCategoryId);
}
},
child: Container(

@ -839,6 +839,7 @@ class _WalaPlusRetailerDetailsScreenState extends State<WalaPlusRetailerDetailsS
}
Widget _buildLocationCard(WalaPlusRetailerLocation loc, bool isAr) {
String distanceText = (loc.distance != null && loc.distance!.trim().isNotEmpty && loc.distance != "null") ? loc.distance!.trim() : "";
String cityText = loc.getLocalizedCity(isAr);
if (cityText.isEmpty) {
cityText = loc.city ?? "";
@ -846,7 +847,12 @@ class _WalaPlusRetailerDetailsScreenState extends State<WalaPlusRetailerDetailsS
String addressText = loc.address ?? "";
String primaryTitle = addressText.isNotEmpty ? addressText : cityText;
String? secondaryText = (addressText.isNotEmpty && cityText.isNotEmpty && addressText.toLowerCase() != cityText.toLowerCase()) ? cityText : null;
String? secondaryText;
if (distanceText.isNotEmpty) {
secondaryText = distanceText;
} else if (addressText.isNotEmpty && cityText.isNotEmpty && addressText.toLowerCase() != cityText.toLowerCase()) {
secondaryText = cityText;
}
return Container(
padding: const EdgeInsets.all(14),

Loading…
Cancel
Save