In POST API call am getting this error "Exception has occurred. _TypeError (type 'String' is not a subtype of type 'Map<String, dynamic>')". here is the code of mine:
model:
class User{
String name;
String emailId;
String password;
User({this.name,this.emailId,this.password});
factory User.fromJson(Map<String, dynamic> responseData){
return User(
name: responseData['name'],
emailId: responseData['email'],
password: responseData['password'],
);
}
}
API Calling:
Future<User> createAlbum() async {
setState(() {
indicator = true;
});
final response = await http.post(
Uri.parse(registerUrl),
body: jsonEncode(<String, String>{
'name': name.text,
'email': email.text,
'password': password.text
}),
);
print(response.body);
if (response.statusCode == 200) {
setState(() {
indicator = false;
});
return User.fromJson(json.decode(response.body));
} else {
throw Exception('Failed to create album.');
}
}
and am getting this error
Exception has occurred. _TypeError (type 'String' is not a subtype of type 'Map<String, dynamic>')
can Any one help me from this?