setAppConfiguration function

Future<void> setAppConfiguration(
  1. AppConfigurationModel res
)

Implementation

Future<void> setAppConfiguration(AppConfigurationModel res) async {
  log("---------------- Saving Data in share preferences ----------------");
  await setValue(PAYMENT_SETTINGS, jsonEncode(res.data?.paymentSettings));
  if (res.data?.inquiryEmail?.isNotEmpty ?? false) {
    appStore.inquiryEmail = res.data!.inquiryEmail!;
  }

  /// set configuration object data
  res.data?.configurations?.forEach((element) {
    if (element.value != null) {
      if (element.key == ADMOB_APP_ID) appStore.setAdmobAppId(element.value.validate());
      if (element.key == ADMOB_BANNER_ID) appStore.setAdmobBannerId(element.value.validate());
      if (element.key == ADMOB_INTERSTITIAL_ID) appStore.setAdmobInterstitialId(element.value.validate());
      if (element.key == CURRENCY_POSITION) appStore.setCurrencyPosition(element.value.validate());
      if (element.key == DISTANCE_TYPE) appStore.setDistanceType(element.value.validate());
      if (element.key == DISTANCE_RADIUS) appStore.setDistanceRadius(element.value.validate());
      if (element.key == TERMS_CONDITION) appStore.setTermsAndCondition(element.value.validate());

      if (element.key == ABOUT_US) appStore.setAboutAS(element.value.validate());

      if (element.key == PRIVACY_POLICY) appStore.setPrivacyPolicy(element.value.validate());
      if (element.key == ONESIGNAL_API_KEY) appStore.setOneSignalAPIKey(element.value.toString());
      if (element.key == ONESIGNAL_REST_API_KEY) appStore.setOneSignalRestAPIKey(element.value.toString());
      if (element.key == CURRENCY_COUNTRY_ID) {
        appStore.setCountryCode(element.country!.code.validate());
        appStore.setCurrencySymbol(element.country!.symbol.validate());
        appStore.setCurrencyCode(element.country!.currencyCode.validate());
      }
      if (element.key == OTHER_SETTING) {
        final otherSetting = OtherSettings.fromJson((jsonDecode(element.value.validate())));
        otherSettingStore.setSocialLoginEnable(otherSetting.socialLogin.validate());
        otherSettingStore.setGoogleLoginEnable(otherSetting.googleLogin.validate());
        otherSettingStore.setAppleLoginEnable(otherSetting.appleLogin.validate());
        otherSettingStore.setFacebookLoginEnable(otherSetting.facebookLogin.validate());
        otherSettingStore.setTiktokLoginEnable(otherSetting.tiktokLogin.validate());
        otherSettingStore.setMaintenanceModeEnable(otherSetting.maintenanceMode.validate());

        compareValuesInSharedPreference(FORCE_UPDATE_FOR_ANDROID_APP, otherSetting.forceUpdateForAndroid);
        compareValuesInSharedPreference(ANDROID_MINIMUM_VERSION, otherSetting.androidMinimumVersion);
        compareValuesInSharedPreference(ANDROID_LATEST_VERSION, otherSetting.androidLatestVersion);
        compareValuesInSharedPreference(FORCE_UPDATE_FOR_IOS_APP, otherSetting.forceUpdateForIos);
        compareValuesInSharedPreference(IOS_MINIMUM_VERSION, otherSetting.iosMinimumVersion);
        compareValuesInSharedPreference(IOS_LATEST_VERSION, otherSetting.iosLatestVersion);
      }
    } else {
      log("element : ${element.key} value is null");
    }
  });

  if (res.data?.generalSettings != null) {
    appStore.nabitInstagramCommunity = res.data?.generalSettings?.instagramUrl ?? "";
    appStore.nabitTwitterCommunity = res.data?.generalSettings?.twitterUrl ?? "";
    appStore.nabitFaceBookCommunity = res.data?.generalSettings?.facebookUrl ?? "";
    appStore.nabitYoutubeCommunity = res.data?.generalSettings?.youtubeUrl ?? "";
    //  appStore.nabitTikTokCommunity = res.data?.generalSettings?.instagramUrl ?? "";
  }

  if (res.data?.appDownload != null) {
    final appLinkData = res.data?.appDownload;
    compareValuesInSharedPreference(PLAY_STORE_LINK, appLinkData?.playstoreUrl.validate());
    compareValuesInSharedPreference(IOS_LINK, appLinkData?.appstoreUrl.validate());
  }
  log("---------------- data Sync is completed ----------------");
}