Home > database >  Having a Socket Exception error in Flutter
Having a Socket Exception error in Flutter

Time:04-08

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. :)

CodePudding user response:

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';
  • Related