In my code has a textfield in there can type name then click button that should pass to http URL and then should get "userID" from that URL.
button code
Future<void> onJoin() async {
setState(() {
myController.text.isEmpty
? _validateError = true
: _validateError = false;
});
Navigator.push(
context,
MaterialPageRoute(builder: (context) => loadData(myController.text)),
);
}
get "userID" from http url
loadData(String myController) async {
var userID = "";
try {
final uri =
Uri.parse('http://github.users.com/$myController');
final response = await http.get(uri);
if (response.userID != null) {
print("userID : " + userID);
}
} catch (e) {
print("Invalid name entered ");
}
}
If successfully retrieve userId then that should print if it null then should display "Invalid name entered ".
Error
2
Answers
Try the following code:
response.body is an encoded json thats why you are getting
so decode your response body, as below