title: why is flutter refusing to connect on localhost:8000 or 127.0.01:8000?
body: <p>I'm following the Flutter Networking/HTTP tutorial to do a GET request to a server running on my localhost:8000. Visiting my localhost via my browser works fine. This works fine too when I point to any real URL, such as <a href="https://example.com" rel="noreferrer">https://example.com</a>, but when I point to <a href="https://127.0.0.1:8000" rel="noreferrer">https://127.0.0.1:8000</a> I get an error like " connection refused "</p>
  
  <p>The port in the error above changes each time I reload the app. I looked in the http package code and it doesn't seem like there is a way to specify the port for the URL. How do I point to my localhost please it's my first time with flutter ?
  PS: i'm running on my phone device , my pc and phone are connected with the same wifi, my network is private.</p>
  
  <pre><code>import 'package:flutter/material.dart';
  import 'dart:async';
  import 'package:http/http.dart' as http;
  import 'dart:convert';
  
  class MyHomePage extends StatefulWidget {
    const MyHomePage({Key key}) : super(key: key);
  
    @override
    _MyHomePageState createState() =&gt; _MyHomePageState();
  }
  
  class _MyHomePageState extends State&lt;MyHomePage&gt; {
  
    static const url = 'http://127.0.0.1:8000/api/membres/';
  
    // static const url = 'http://10.0.2.2:8000/api/membres/';
    //static const url = 'http://localhost:8000/api/membres/';
    //static const url= "192.168.1...:8000/association/api/membres";
    //static const url = 'https://jsonplaceholder.typicode.com/users';
    Future&lt;List&lt;Map&lt;String, dynamic&gt;&gt;&gt; _future;
  
    @override
    void initState() {
      super.initState();
      _future = fetch();
    }
  
    Future&lt;List&lt;Map&lt;String, dynamic&gt;&gt;&gt; fetch() {
      return http
          .get(url)
          .then((response) {
            return response.statusCode == 200
                ? response.body
                : throw 'Error when getting data';
          })
          .then((body) =&gt; json.decode(body))
          .then((list) =&gt; (list as List).cast&lt;Map&lt;String, dynamic&gt;&gt;());
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          title: Text('Home'),
        ),
        body: RefreshIndicator(
          onRefresh: () async {
            _future = fetch();
            setState(() {});
            return _future;
            },
          child: FutureBuilder&lt;List&lt;Map&lt;String, dynamic&gt;&gt;&gt;(
            future: _future,
            builder: (context, snapshot) {
              if (snapshot.hasError) {
                return Center(
                  child: Container(
                    constraints: BoxConstraints.expand(),
                    child: SingleChildScrollView(
                      physics: AlwaysScrollableScrollPhysics(),
                      child: Text(snapshot.error.toString()),),),);}
              if (!snapshot.hasData) {
                return Center(
                  child: CircularProgressIndicator(),
                );}
              return ListView.builder(
                itemCount: snapshot.data.length,
                itemBuilder: (BuildContext context, int index) {
                  final item = snapshot.data[index];
                  return ListTile(
                    title: Text(item['name']),
                    subtitle: Text(item['email']),
                  );
                },
              );
            },
          ),
        ),
      );
    }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/YgP8k.png" rel="noreferrer"><img src="https://i.stack.imgur.com/YgP8k.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/2kH3g.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2kH3g.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/5yyue.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5yyue.png" alt="enter image description here"></a></p>