How to open localhost in flutter webview
Asked Answered
D

2

7

What I m trying:

Open a local host in flutter WebView. I am using This plugin and this project is running in Django with URL: http://127.0.0.1:8000/. I want to open this in my flutter app.

What I have tried:

After searching SO answers, URL: http://myIPaddress:8000/.

UPDATE

I am providing internet from mobile.

This is my local IP address

I am using http://192.168.43.55:8080/ is not working and also http://192.168.43.1:8080/

Any suggestion will work, thanks.

Dancer answered 20/6, 2020 at 22:19 Comment(8)
What's not working? http://127.0.0.1:8000/. is not going to work as it's localhost in the device where you run the app and not the server localhost. http://myIPaddress:8000/. where myIPaddress is the ip of the server in the same network as the device, should work unless I miss something.Frequentation
http://myIPaddress:8000/ is not workingDancer
Have you tested http://myIPaddress:8000/ in desktop and mobile browser? Does it work?Frequentation
Are you running / debugging in the Android emulator, the iOS simulator, on on device? In the Android emulator, you'd have to use a 10.0.2.2 based address - see developer.android.com/studio/run/emulator-networking. For simulator, it should work as you have it. For device, see comment above from Claudio (there may be other options, but that might be simplest).Gilbertogilbertson
Yes. In desktop and mobile, nothing is working.Dancer
Yes, I have already gone through this. but I m using a physical device.which is my mobile and also from this device I'm providing internet to the desktop.Dancer
What are you using in as myIPaddress? if http://127.0.0.1:8000/ works in the desktop, replacing 127.0.0.1 by a valid local ip should work too.Frequentation
I have Updated the Question with myIPaddress but nothing works for me.Dancer
F
8

Try with http://10.0.2.2:8000. If you get a cleartext error, in your AndroidManifest.xml add android:usesCleartextTraffic="true" under the application tag

Fakir answered 20/12, 2020 at 8:57 Comment(0)
D
0

With Android emulator, you can access the localhost by providing the IPv4 with http:// that means http://192.168.43.55:8080/ should be accessible from your flutter webview application.

Davidoff answered 8/7, 2021 at 5:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.