Why http.get is throwing error in Flutter


The error message that is showing in Dev toolsI am trying to execute a PHP file in Flutter.
The code that I have is:

class _MyAppState extends State<MyApp> {
  var url = 'http://localhost/myDashFolder/getdata.php';

  Future<List> getData() async {
    final response = await http.get(Uri.parse(url));
    if (response.statusCode == 200) {
      return json.decode(response.body);
    else {
      throw Exception("Response content length is ${response.statusCode}, failed to get any details.");

In Dev tools, the get request is showing an error. However, when I execute the same manually, it works.

What am I doing wrong?


url =

Try using the above URL in your emulator.

Source : LINK
Comment if the solution does not work.

Answered By – Nagulan S

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *