i am trying to do an http request with flutter, with the konamicash.com/connexion_bdd_flutter, i have no answer even no error, but with the same code with the url of
https://jsonplaceholder.typicode.com/todos/1
echo json_encode(["message"=>"requete ok"]);
?>
fetchData() async { var url = Uri.parse('https://konamicash.com/connexion_bdd_flutter'); var response = await http.get(url);
}
if (response.statusCode == 200) {
print('sa fonctionne: ${response.body}');
} else {
print('error');
}
}
2
Answers
Import http package as
Try below code with try/catch block for errors and data response.
I’ve tested your function, and it’s working properly. However, in your function, there were syntax mistakes, and the condition was placed outside the function.
I’ve made some corrections to your code and added certain changes. However, I recommend following proper syntax when working with Future. Below, I’ve redefined your function correctly.
I’ve defined the return type of the function and added a try-catch block for error handling.