0

I have a flutter app starting a webserver (shelf) on localhost which serves a website and displays the website over webview in the app. So far it works to display the website over http://localhost:8080/ in webview on Android. But when I try to get the IP address of the device in my application with NetworkInfo (package:network_info_plus/network_info_plus.dart) on webview it shows "net::ERR_CONNECTION_REFUSED".

WidgetsFlutterBinding.ensureInitialized();

runApp(MyApp());

await Permission.location.request();
final info = NetworkInfo();
var hostAddress = await info.getWifiIP();

I already set these permissions in AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

Testing on Android Device, when I open a webpage over https it will work. Also it will work when I testing it on windows.

Does anyone have an idea what causes the problem on Android?

1 Answers1

0

For me it solved the problem when first ask about the network info before run the app.

final info = NetworkInfo();
var hostAddress = await info.getWifiIP();

runApp(MyApp());