How to point to localhost:8000 with the Dart http package in Flutter?

前端 未结 9 1097
野趣味
野趣味 2020-12-10 00:34

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. My code lo

9条回答
  •  悲&欢浪女
    2020-12-10 01:15

    replace 'localhost' in your url to wifi connection ip e.g : 'http://localhost:8000' => 'http://192.168.1.102:8000'. you can get your wifi ip from command prompt with cmd>ipconfig (wireless LAN adapter WI-FI.

    var url = 'http://192.168.1.102:8000';
    Future getUnits(String category) async {
        var response = await httpClient.get('$url/$category');
        return response.body;
    }
    

提交回复
热议问题