I am trying to sign up a user by posting to the endpoint with the required data, it works perfectly but the API returns an error message of fullName
is required. As you can see clearly, I am passing the name to the fullName
in the call.
Future<Map<String, dynamic>> signup({
required String name,
required String email,
required String password,
}) async {
try {
Response response = await dio.post(Api.SIGN_UP, data: {
'fullName': name,
'email': email,
'password': password,
});
final responseData = response.data;
print(responseData.toString());
return responseData;
} on DioError catch (err) {
print(err.error);
throw CustomException(err.message);
} catch (error) {
throw CustomException('An error occured. Please try again later');
}
}
Below is the endpoint I want to make the call to:
class Api {
// DIO OPTIONS
static var options = BaseOptions(
baseUrl: 'http://localhost:3000/api/',
connectTimeout: 5000,
receiveTimeout: 3000,
);
static const SIGN_UP = 'onboarding/signup';
}
I tried in using postman to do it and it works correctly and signs up the user. I don't know where the error is coming from, whether the Dio or the backend.
CodePudding user response:
add this to headers
"Accept": "application/json",
CodePudding user response:
Add response type, and content type to your deo option
static var options = BaseOptions(
baseUrl: 'http://localhost:3000/api/',
connectTimeout: 5000,
receiveTimeout: 3000,
responseType: ResponseType.plain,
contentType: Headers.jsonContentType,
);