fetchUserProfile method

void fetchUserProfile(
  1. BuildContext context
)

Implementation

void fetchUserProfile(BuildContext context) async {
  try {
    isLoading(true);
    var request = {
      'token': Storage.getValue(Constants.token),
      'api_key': Constants.apiKey,
      'sub_client_api_key': Storage.getValue(Constants.subClientApiKey)
    };
    var response = await DioClient().request(
        context: context, api: '/me', method: Method.POST, params: request);

    MeResponse meResponse = MeResponse.fromJson(response);
    if (meResponse.status == Strings.success) {
      user = meResponse.data!.user!.obs;
      isError(false);
    } else {
      isError(true);
      errorMessage.value = response['message'].toString().toTitleCase();
      if (errorMessage.value == 'Token Not Valid') {
        Utils.navigationReplace(context, const Login());
        return Utils.showSnackbar(
            context, Strings.error, 'Token has expired please login again!.', AppColors.red);
      }
      return Utils.showSnackbar(context, Strings.error,
          response['message'].toString().toTitleCase(), AppColors.red);
    }
  } finally {
    isLoading(false);
  }
  update();
}