From dbc92e9e29309a0914a1098f047f71aeccd2a59c Mon Sep 17 00:00:00 2001 From: Sultan khan Date: Wed, 11 Nov 2026 12:49:39 +0300 Subject: [PATCH] last login dependent updated --- lib/ui/mazaya/mazaya_discover_screen.dart | 65 +++++++++++++++++++++-- lib/ui/mazaya/retailers_list_screen.dart | 2 +- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/lib/ui/mazaya/mazaya_discover_screen.dart b/lib/ui/mazaya/mazaya_discover_screen.dart index 34c3df41..3f1c4b06 100644 --- a/lib/ui/mazaya/mazaya_discover_screen.dart +++ b/lib/ui/mazaya/mazaya_discover_screen.dart @@ -4,6 +4,7 @@ import 'dart:convert'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import 'package:mohem_flutter_app/api/login_api_client.dart'; import 'package:mohem_flutter_app/api/offers_and_discounts_api_client.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; @@ -48,7 +49,7 @@ class _MazayaDiscoverScreenState extends State { bool _isLoadingCategories = true; List _categories = []; - + bool _hasRegisteredMobileLoginInfo = false; bool _isLoadingExclusiveOffers = true; List _exclusiveOffers = []; @@ -70,6 +71,7 @@ class _MazayaDiscoverScreenState extends State { _fetchCategories(); _fetchExclusiveOffers(); _initCityAndFetchSections(); + _registerMobileLoginInfo(); } Future _initCityAndFetchSections() async { @@ -101,10 +103,63 @@ class _MazayaDiscoverScreenState extends State { super.dispose(); } - // Only drives the benefits strip now - Travel Essentials/Home & Kitchen/Latest on Mazaya each - // fetch independently (see _fetchCategorySection/_fetchLatestOnMazaya). Still fetched in - // parallel with those though, since it also feeds each fixed-category section's title (the - // top-level categories list is the primary source there - see _sectionTitle). + Future _registerMobileLoginInfo() async { + if (_hasRegisteredMobileLoginInfo) return; + if (!ApiConsts.isDependetLogin) return; + _hasRegisteredMobileLoginInfo = true; + + try { + int loginType = AppState().dependentLoginType ?? 1; + String nationalId = AppState().getUserName ?? ""; + String dob = AppState().dependentDob ?? ""; + String name = AppState().dependentName ?? ""; + String mobile = AppState().postParamsObject?.mobileNumber ?? ""; + String tokenID = + (AppState().postParamsObject?.tokenID != null && + AppState().postParamsObject!.tokenID!.isNotEmpty) + ? AppState().postParamsObject!.tokenID! + : (AppState().authenticationTokenID ?? ""); + if (tokenID.isEmpty) { + tokenID = await Utils.getStringFromPrefs("P_DEP_TOKEN_ID"); + } + int sessionId = AppState().postParamsObject?.pSessionId ?? 0; + String email = AppState().postParamsObject?.pEmailAddress ?? ""; + String deviceToken = + AppState().getIsHuawei + ? AppState().getHuaweiPushToken + : ((AppState().getDeviceToken != null && + AppState().getDeviceToken!.isNotEmpty && + AppState().getDeviceToken != "null") + ? AppState().getDeviceToken! + : ""); + if (deviceToken.isEmpty || deviceToken == "null") { + String savedToken = await Utils.getStringFromPrefs( + "P_DEP_DEVICE_TOKEN", + ); + if (savedToken.isNotEmpty && savedToken != "null") { + deviceToken = savedToken; + } + } + + await LoginApiClient().insertMobileLoginInfoDependent( + loginType: loginType, + nationalId: nationalId, + dob: dob, + dependentName: name, + mobileNumber: mobile, + tokenID: tokenID, + sessionId: sessionId, + email: email, + deviceToken: deviceToken, + channel: AppState().postParamsObject?.channel, + context: context, + ); + } catch (e) { + // if (kDebugMode) { + print("Error calling insertMobileLoginInfoDependent: $e"); + // } + } + } Future _fetchCategories() async { setState(() => _isLoadingCategories = true); try { diff --git a/lib/ui/mazaya/retailers_list_screen.dart b/lib/ui/mazaya/retailers_list_screen.dart index 64156e3a..e39f9b85 100644 --- a/lib/ui/mazaya/retailers_list_screen.dart +++ b/lib/ui/mazaya/retailers_list_screen.dart @@ -100,7 +100,7 @@ class _RetailersListScreenState extends State { WidgetsBinding.instance.addPostFrameCallback((_) async { if (mounted) { await _saveDependentSessionToPrefs(); - await _registerMobileLoginInfo(); + await fetchCategories(); } });