Flutter How to Pass Path Parameter with Dio

In flutter development, Sometimes we need to pass Path parameters in an HTTP request using the DIO HTTP package, I will share with you a very small but more helpful tutorial, How to pass path parameters in the HTTP request with Dio.

How to pass path parameter with Dio : 

var response = await BaseClient().get(Url.FORGOT_PASSWORD_URL+email, body)

Here, FORGOT_PASSWORD_URL is your API URL and email is your path parameter value (Don't put your path variable key direct put value).

 

Example :

  var response = await BaseClient()
        .get(Url.FORGOT_PASSWORD_URL+email, body)//
        .catchError(handleError);
    if (response == null) return;
    commonResponse.value = commonResponseFromJson(response);
    // hideLoading();
    if (commonResponse.value.isSuccess) {
    
       //....
   } else {
      Utility.showSnackBar(commonResponse.value.message,
          dataType: Strings.SNACK_BAR_ERROR,
          backColor: AppColors.colorErrorSnackBar);
    }

 

Conclusion:

We learned in Flutter How to Pass the Path Parameter with Dio. I hope this post may help you.

Tags: