onUserStateUpdated method
Future<void>
onUserStateUpdated(
)
Implementation
Future<void> onUserStateUpdated() async {
final response = await cacheInstance.getValue(cdnConfigInstance.getKeys(StorageKeyKeys.gkVerifiedUserKey)!);
if (response == null) {
// onErrorData?.call(FlowResult(
// flowType: FlowType.notLoggedIn, error: 'User Not Logged In'));
return;
}
final Map<String, dynamic> responseData = jsonDecode(response);
final isShopifyOrCustomShopify =
state.merchantType == "shopify" ||
state.merchantType == "custom_shopify";
if (isShopifyOrCustomShopify) {
if (
// responseData['emailRequired'] == true &&
(responseData['email'] == null || responseData['email'].isEmpty)) {
emit(state.copyWith(isNewUser: true));
if (responseData['multipleEmail'] != null) {
final multipleEmails = (responseData['multipleEmail'] as String)
.split(',')
.map((email) => email.trim())
.toList();
emit(state.copyWith(
multipleEmails: multipleEmails
.map((email) => MultipleEmail(label: email, value: email))
.toList()));
}
return;
}
if ((responseData['shopifyCustomerId'] != null &&
responseData['phone'] != null &&
responseData['email'] != null
// &&
// responseData['multipassToken'] != null
) ||
(responseData['shopifyCustomerId'] != null &&
responseData['phone'] != null &&
responseData['email'] != null &&
// responseData['multipassToken'] != null &&
responseData['password'] != null)) {
onSuccessData?.call(
FlowResult(flowType: FlowType.alreadyLoggedIn, data: responseData));
emit(state.copyWith(isUserLoggedIn: true));
if (onAnalytics != null) {
// onAnalytics!(
// cdnConfigInstance.getAnalyticsEventOrDefault(AnalyticsEvents.appIdentifiedUser),
// {
// 'phone': responseData['phone'],
// 'email': responseData['email'],
// 'customer_id':
// responseData['shopifyCustomerId'] ?? (responseData['id'] ?? ""),
// },
// );
}
return;
}
}
if (state.merchantType == "custom") {
if (responseData['emailRequired'] == true &&
(responseData['email'] == null || responseData['email'].isEmpty)) {
emit(state.copyWith(isNewUser: true));
return;
}
if (responseData['phone'] != null && responseData['email'] != null) {
emit(state.copyWith(isUserLoggedIn: true));
return;
}
}
}