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
If you are using an Android emulator then localhost on the emulator is not 127.0.0.0 it is 10.0.2.2, so, on Android emulator you need to write https://10.0.2.2:8000, the https://127.0.0.1:8000 will not work on real device too. because localhost means something different on real device.
For more information on how to connect a Flutter app to localhost on emulator or on a real device click on the link Connecting Flutter application to Localhost
Replacing the string localhost with 10.0.2.2 resolved it for me, since I was running the code in the Android emulator, which is running in a VM. It's essentially a duplicate of this question.
to find ip is ifconfig mac / linux
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
this one => inet 192.168.43.57 netmask 0xffffff00 broadcast 192.168.43.255
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
start php
php -S 192.168.43.57:5000 index.php
than declare on future
Future<String> 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"}]