Home > Back-end >  How to make post request as form-data with Get x package in flutter?
How to make post request as form-data with Get x package in flutter?

Time:04-29

Hi i need to send signup body as form-data in flutter with getx.

here is my model clas

class SignupBody {
int? responseStatus;
String? message;
String? userId;
String? name;
String? email;
String? role;
String? country;
File? photo;
String? university;
List<String>? qualification;
List<String>? interests;

SignupBody(
  {this.responseStatus,
  this.message,
  this.userId,
  this.name,
  this.email,
  this.role,
  this.country,
  this.photo,
  this.university,
  this.qualification,
  this.interests});  
}

i need to post this body as form-data how can i post as form-data ?

CodePudding user response:

You can use dio package to send formData.

  • First make formdata

    var formData = await formDataMap(
      checkbox: checkbox,
      taskDetail: _task,
      pageNumber: _currentQuestion.value,
      valueString: value,
      valueType: valueType,
      formFieldInstanceID:
      task.formFields[_currentQuestion.value].formFieldInstanceId,
    );
    
  • Then add it in data parameter of dio_client Example

     _dio.putUri(
     Uri.parse(uri),
     data: data,
    

    );

CodePudding user response:

You can use FormData(map) from get package.

FormData formdata = FormData(map);
post(url, formdata);
  • Related