last login dependent updated

master^2
Sultan khan 8 hours ago
parent 3a31b8f430
commit dbc92e9e29

@ -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<MazayaDiscoverScreen> {
bool _isLoadingCategories = true;
List<WalaPlusCategoryModel> _categories = <WalaPlusCategoryModel>[];
bool _hasRegisteredMobileLoginInfo = false;
bool _isLoadingExclusiveOffers = true;
List<WalaPlusRetailerModel> _exclusiveOffers = <WalaPlusRetailerModel>[];
@ -70,6 +71,7 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
_fetchCategories();
_fetchExclusiveOffers();
_initCityAndFetchSections();
_registerMobileLoginInfo();
}
Future<void> _initCityAndFetchSections() async {
@ -101,10 +103,63 @@ class _MazayaDiscoverScreenState extends State<MazayaDiscoverScreen> {
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<void> _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<void> _fetchCategories() async {
setState(() => _isLoadingCategories = true);
try {

@ -100,7 +100,7 @@ class _RetailersListScreenState extends State<RetailersListScreen> {
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (mounted) {
await _saveDependentSessionToPrefs();
await _registerMobileLoginInfo();
await fetchCategories();
}
});

Loading…
Cancel
Save