My App can authenticate successfully when debugging against the Android emulator, but if I try to authenticate using debugging against the physical device (with same OS version), an error message appears after more than one minute waiting:
Exception has occurred.
_TypeError (type 'String' is not a subtype of type 'int' of 'index')
The error message points to the following code:
if (responseJson[AuthUtils.authTokenKey] != null) {
AuthUtils.insertDetails(
userNameController.text, passwordController.text, responseJson);
...
} else {
...
};
And in the DEBUG CONSOLE I get the following:
I/flutter ( 9531): Auth: SocketException: OS Error: Connection timed out, errno = 110, address = example.com, port = 38975 V/InputMethodManager( 9531): Starting input: tba=android.view.inputmethod.EditorInfo@4aece4e nm : example.com.todoapp ic=null
Here is the screenshot:
What am I doing wrong here ?
For my case responseJson was of dynamic data type what i did was to cast it to string.
change this
responseJson[AuthUtils.authTokenKey]
to this
String jsonsDataString = responseJson.toString();
final jsonData = jsonDecode(jsonsDataString);
//then you can get your values from the map
if(jsonData[AuthUtils.authTokenKey] != null){
...
}
I believe that in the line:
responseJson[AuthUtils.authTokenKey]
You're referencing an item in the list responseJson by the index AuthUtils.authTokenKey
And since AuthUtils.authTokenKey is a String, you cannot use it as in index of an array.
So you need first to get the index of AuthUtils.authTokenKey then use it to reference the item:
responseJson[responseJson.indexOf(AuthUtils.authTokenKey)]
This worked for me. I was doing this in flutter.
http.Response S=await
http.get("Your link here");
String responseBody = S.body;
dynamic jsonObject = jsonDecode(jsonDecode(S.body));
print(jsonObject[0]["product_id"]);
setState(() {
data=jsonObject[0]["product_id"];
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With