11

Making a login screen in flutter when i tap the login it gives the error 'network is Unreachable'.

I have change the ip addresses "10.0.2.2" , "8.7.7.7" but doesn't work.

Error :

E/flutter (16082): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled 
Exception: SocketException: Connection failed 
(OS Error: Network is unreachable, errno = 101), address = 10.0.2.2, port = 80

CODE :

TextEditingController user=new TextEditingController();
TextEditingController pass=new TextEditingController();

Future<List> _login() async{
  final response = await http.post("http://127.0.0.1/my_store/login.php", body: {
    "username": user.text,
    "password": pass.text,
   
  });

  print(response.body);
  }

3
  • 1
    We need some code to be able to help you. Commented Jun 25, 2019 at 16:06
  • @MartinNiederl Should i provide the whole script ? Commented Jun 28, 2019 at 11:03
  • Depending on whether your device is running in an emulator or on an external device, the IP address for accessing the local server must be adjusted. Here's a little explanation: stackoverflow.com/a/34732276/6513167 I don't know your setup, so I also don't know how to reach your local server. Commented Jun 29, 2019 at 10:54

5 Answers 5

18

In my case turning on the wifi and making sure that it is connected solved the issue.enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Discovering this forced me to create the (long overdue) network and internet connectivity features for my app. Hopefully it won't catch me again!
15

Turning OFF the Wi-fi on emulator helped me!

1 Comment

Worked for me, too. Thanks very much! This was strange, because other API calls were working to prove valid internet connection but only one was failing.
3

if you are using a physical device make sure the ip address is the ip of your computer. you can find it by running ipconfig in cmd. Remember you have to be connected to the internet to have this ip address.

Comments

1

I have searched some threads about this and similar connection problems. In my case, sometimes the connection works, sometimes it refuses to work. The process I used to solve this problem was the following:

Open cmd -> ipconfig

the ip that is relevant for my solution

Since I am using an Apache server, and I have a php file that handles the request I make in Flutter, I set the url to the following:

 String url="http://192.168.0.137/login.php"

In your case, the code would be

    TextEditingController user=new TextEditingController();
    TextEditingController pass=new TextEditingController();

    Future<List> _login() async{
      final response = await http.post("http://<your_ipv4_of_ipconfig>/my_store/login.php", body: {
        "username": user.text,
        "password": pass.text,

      });

      print(response.body);
      }

Comments

0

After many hours of head scratching, in my case it was the data connection icon was turned off by mistake cutting all sorts of data streams to vm :~

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.