0

today I got an error likt this.

E/flutter ( 3624): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: SocketException: Failed host lookup: 'http' (OS Error: No address associated with hostname, errno = 7)

my code using http protocol is only this.

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  var deliveryInfoDecode = jsonDecode(
      '[{"no":"", "date":"","car number":"",  "driver":"", "center":"", "register id":""}]');
  String myUrl = 'http://172.30.1.14/';

  Future<void> getDelivery() async {
    String apiurl = 'http://' + myUrl + '/DeliverOrder.php';
    var res = await http.get(Uri.parse(apiurl));
    var resBody = json.decode(res.body);

    setState(() {
      deliveryInfoDecode = resBody;
    });
  }

I already add Internet permission on my androidmanifest.xml and also check url. it works well.

Thank you for your help. :)

1 Answer 1

1

Variable myUrl already contains String 'http://' but you are adding it again to variable apiurl so it throws error. It should be something like:

String myUrl = 'http://172.30.1.14/';
String apiurl = myUrl + 'DeliverOrder.php';
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I checked many times, but I missed it.

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.