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

前端 未结 9 1103
野趣味
野趣味 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:32

    to find ip is ifconfig mac / linux

    en0: flags=8863 mtu 1500
    
    
        this one => inet 192.168.43.57 netmask 0xffffff00 broadcast 192.168.43.255
    
        nd6 options=201
        media: autoselect
        status: active
    

    start php

    php -S 192.168.43.57:5000 index.php

    than declare on future

    Future getIsi()async{
          final res = await new Dio().get('http://192.168.43.57:5000/lihat-isi');
          print('res.data');
          return res.data;
        }
    

    an result is

    I/flutter ( 3250): [{"id":"1","judul":"asasa","gambar":"asa","ket":"asa"},{"id":"2","judul":"asasa","gambar":"asa","ket":"asa"},{"id":"3","judul":"asasa","gambar":"asa","ket":"asa"},{"id":"4","judul":"asasa","gambar":"asa","ket":"asa"}]
    

提交回复
热议问题