|
|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
@ -65,7 +66,7 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
|
|
|
|
|
|
|
|
|
|
// Fixed-category sections - to point a section at a different category, change only the id
|
|
|
|
|
// passed here. Everything else (fetch, title, UI) reads off the _MazayaCategorySection object.
|
|
|
|
|
final _MazayaCategorySection _travelSection = _MazayaCategorySection('Q4');
|
|
|
|
|
final _MazayaCategorySection _travelSection = _MazayaCategorySection('p03');
|
|
|
|
|
final _MazayaCategorySection _homeKitchenSection = _MazayaCategorySection(
|
|
|
|
|
'Bw',
|
|
|
|
|
);
|
|
|
|
|
@ -73,11 +74,33 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
selectedCity = AppState().selectedMazayaCity;
|
|
|
|
|
_fetchCategories();
|
|
|
|
|
_fetchExclusiveOffers();
|
|
|
|
|
_fetchLatestOnMazaya();
|
|
|
|
|
_fetchCategorySection(_travelSection);
|
|
|
|
|
_fetchCategorySection(_homeKitchenSection);
|
|
|
|
|
_initCityAndFetchSections();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _initCityAndFetchSections() async {
|
|
|
|
|
if (selectedCity == null) {
|
|
|
|
|
String savedCityJson = await Utils.getStringFromPrefs("MAZAYA_SELECTED_CITY");
|
|
|
|
|
if (savedCityJson.isNotEmpty && mounted) {
|
|
|
|
|
try {
|
|
|
|
|
WalaPlusCityModel city = WalaPlusCityModel.fromJson(jsonDecode(savedCityJson));
|
|
|
|
|
if (!city.isAllCities) {
|
|
|
|
|
AppState().setSelectedMazayaCity = city;
|
|
|
|
|
selectedCity = city;
|
|
|
|
|
if (mounted) setState(() {});
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
debugPrint("Error restoring saved city: $e");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (mounted) {
|
|
|
|
|
_fetchLatestOnMazaya();
|
|
|
|
|
_fetchCategorySection(_travelSection);
|
|
|
|
|
_fetchCategorySection(_homeKitchenSection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
@ -185,9 +208,15 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
|
|
|
|
|
// embedded in each retailer (kept as a fallback for when the id isn't in the top-level list).
|
|
|
|
|
// fallbackTitle only shows while neither source has resolved a name yet.
|
|
|
|
|
String _sectionTitle(_MazayaCategorySection section, String fallbackTitle) {
|
|
|
|
|
bool isAr = mounted ? AppState().isArabic(context) : false;
|
|
|
|
|
for (WalaPlusCategoryModel c in _categories) {
|
|
|
|
|
if (c.id == section.categoryId && (c.name ?? '').isNotEmpty) {
|
|
|
|
|
return c.name!;
|
|
|
|
|
if (c.id == section.categoryId) {
|
|
|
|
|
if (isAr && c.countryNameAr != null && c.countryNameAr!.trim().isNotEmpty) {
|
|
|
|
|
return c.countryNameAr!.trim();
|
|
|
|
|
}
|
|
|
|
|
if ((c.name ?? '').isNotEmpty) {
|
|
|
|
|
return c.name!;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (section.resolvedName != null && section.resolvedName!.isNotEmpty) {
|
|
|
|
|
@ -261,8 +290,8 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _openRetailersGrid({WalaPlusCategoryModel? category}) {
|
|
|
|
|
Navigator.pushNamed(
|
|
|
|
|
Future<void> _openRetailersGrid({WalaPlusCategoryModel? category}) async {
|
|
|
|
|
await Navigator.pushNamed(
|
|
|
|
|
context,
|
|
|
|
|
AppRoutes.retailersListScreen,
|
|
|
|
|
// Carries the currently selected city along so RetailersListScreen starts on it instead
|
|
|
|
|
@ -272,13 +301,19 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
|
|
|
|
|
if (selectedCity != null) 'city': selectedCity,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
if (mounted && selectedCity?.cityId != AppState().selectedMazayaCity?.cityId) {
|
|
|
|
|
setState(() => selectedCity = AppState().selectedMazayaCity);
|
|
|
|
|
_fetchLatestOnMazaya();
|
|
|
|
|
_fetchCategorySection(_travelSection);
|
|
|
|
|
_fetchCategorySection(_homeKitchenSection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exclusive offers reuse the legacy Offers & Discounts API (see fetchExclusiveOffers in both
|
|
|
|
|
// this screen and RetailersListScreen), so "See all" opens RetailersListScreen's exclusive
|
|
|
|
|
// mode instead of a WalaPlus category.
|
|
|
|
|
void _openExclusiveOffersGrid() {
|
|
|
|
|
Navigator.pushNamed(
|
|
|
|
|
Future<void> _openExclusiveOffersGrid() async {
|
|
|
|
|
await Navigator.pushNamed(
|
|
|
|
|
context,
|
|
|
|
|
AppRoutes.retailersListScreen,
|
|
|
|
|
arguments: <String, dynamic>{
|
|
|
|
|
@ -286,13 +321,19 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
|
|
|
|
|
if (selectedCity != null) 'city': selectedCity,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
if (mounted && selectedCity?.cityId != AppState().selectedMazayaCity?.cityId) {
|
|
|
|
|
setState(() => selectedCity = AppState().selectedMazayaCity);
|
|
|
|
|
_fetchLatestOnMazaya();
|
|
|
|
|
_fetchCategorySection(_travelSection);
|
|
|
|
|
_fetchCategorySection(_homeKitchenSection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tapping the search field opens the same "all categories / newest" data as "Latest on
|
|
|
|
|
// Mazaya"'s See all, but with the category hero hidden and the search bar auto-focused with
|
|
|
|
|
// the keyboard open (see RetailersListScreen's isSearchMode) instead of landing on Travel.
|
|
|
|
|
void _openSearchGrid() {
|
|
|
|
|
Navigator.pushNamed(
|
|
|
|
|
Future<void> _openSearchGrid() async {
|
|
|
|
|
await Navigator.pushNamed(
|
|
|
|
|
context,
|
|
|
|
|
AppRoutes.retailersListScreen,
|
|
|
|
|
arguments: <String, dynamic>{
|
|
|
|
|
@ -304,6 +345,12 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
|
|
|
|
|
if (selectedCity != null) 'city': selectedCity,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
if (mounted && selectedCity?.cityId != AppState().selectedMazayaCity?.cityId) {
|
|
|
|
|
setState(() => selectedCity = AppState().selectedMazayaCity);
|
|
|
|
|
_fetchLatestOnMazaya();
|
|
|
|
|
_fetchCategorySection(_travelSection);
|
|
|
|
|
_fetchCategorySection(_homeKitchenSection);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _onRefresh() async {
|
|
|
|
|
@ -326,6 +373,7 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
|
|
|
|
|
await Utils.removeStringFromPrefs("P_DEP_MOBILE_NUMBER");
|
|
|
|
|
await Utils.removeStringFromPrefs("P_DEPENDENT_NAME");
|
|
|
|
|
await Utils.removeStringFromPrefs("P_DEP_LOGIN_TYPE");
|
|
|
|
|
await Utils.removeStringFromPrefs("MAZAYA_SELECTED_CITY");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Same app bar actions as the previous dependent-login landing page
|
|
|
|
|
@ -349,6 +397,8 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
|
|
|
|
|
AppState().setDependentDob = null;
|
|
|
|
|
AppState().setDependentLoginType = null;
|
|
|
|
|
AppState().setWalaplusDepInfoModel = null;
|
|
|
|
|
AppState().setSelectedMazayaCity = null;
|
|
|
|
|
await Utils.removeStringFromPrefs("MAZAYA_SELECTED_CITY");
|
|
|
|
|
AppState().setPostParamsInitConfig();
|
|
|
|
|
if (mounted) {
|
|
|
|
|
Navigator.pushNamedAndRemoveUntil(
|
|
|
|
|
@ -407,11 +457,11 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
|
|
|
|
|
appBar: AppBarWidget(
|
|
|
|
|
context,
|
|
|
|
|
title: LocaleKeys.mazayaDeals.tr(),
|
|
|
|
|
showHomeButton: false,
|
|
|
|
|
showHomeButton: true,
|
|
|
|
|
// Discover is the dependent-login landing page - no back button there (logout is still
|
|
|
|
|
// reachable via the explicit logout action below). Employees reaching Discover from the
|
|
|
|
|
// regular dashboard can still pop back normally.
|
|
|
|
|
showBackButton: !ApiConsts.isDependetLogin,
|
|
|
|
|
showBackButton: false,
|
|
|
|
|
onBackTapped: () {
|
|
|
|
|
if (Navigator.canPop(context)) {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
@ -587,7 +637,17 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
|
|
|
|
|
context,
|
|
|
|
|
selectedCityId: selectedCity?.cityId,
|
|
|
|
|
onCitySelected: (city) {
|
|
|
|
|
setState(() => selectedCity = city);
|
|
|
|
|
WalaPlusCityModel? newCity = city.isAllCities ? null : city;
|
|
|
|
|
AppState().setSelectedMazayaCity = newCity;
|
|
|
|
|
if (newCity != null) {
|
|
|
|
|
Utils.saveStringFromPrefs(
|
|
|
|
|
"MAZAYA_SELECTED_CITY",
|
|
|
|
|
jsonEncode(newCity.toJson()),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.removeStringFromPrefs("MAZAYA_SELECTED_CITY");
|
|
|
|
|
}
|
|
|
|
|
setState(() => selectedCity = newCity);
|
|
|
|
|
_fetchLatestOnMazaya();
|
|
|
|
|
_fetchCategorySection(_travelSection);
|
|
|
|
|
_fetchCategorySection(_homeKitchenSection);
|
|
|
|
|
|