class AuthenticationApi {
final dio = Dio(BaseOptions(baseUrl: FlavorApi.getBaseUrl()));
Future<dynamic> login(
{required String email, required String password}) async {
try {
FormData formData = FormData.fromMap(
{'email': email, 'password': password, 'ip': '127.0.0.1'});
final response = await dio.post(
'/login?oauth_consumer_key=${FlavorApi.getConsumerKey()}&oauth_consumer_secret=${FlavorApi.getConsumerSecret()}',
data: formData);
var responseData = jsonDecode(response.data); //error is coming here
print('Data = $responseData');
} on DioError catch (e) {
print(e.message);
}
}
}
When I convert data into JSON format I am getting the error Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'.
I tried many solutions but it is not fixing can anyone help me why this error is coming with dio package. you can see the issue image below:
CodePudding user response:
The jsonDecode method creates a Map from a String. Your response.data is already a Map.
You can check the method here.
Also, I recommend you check JSON Serialization. It is on the same page with the jsonDecode, but here is a specific link.
I hope that my answer will help you! :)