'Flutter - Webview in DEBUG is working but it's displaying blank on RELEASE apk, why?
I was working with flutter with this webviews package https://pub.dev/packages/webview_flutter .
The webview in debug mode runs fine (I use an emulator can't use debug on actual device due to incompatible USB) but it only shows grayish blank screen. I also have tried iserting permission in AndroidManifest.xml :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Here's the code :
class _WebViewHereClass extends State<WebViewHereClassState> {
final String _url;
bool isLoading=true;
final _key = UniqueKey();
_WebViewHereClass(this._url);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Flex(
direction: Axis.vertical,
children: [
Expanded(
flex: 1,
child: WebView(
key: _key,
javascriptMode: JavascriptMode.unrestricted,
initialUrl: _url,
onPageFinished: (finish) {
setState(() {
isLoading = false;
});
},
)
),
],
),
isLoading ? const Center(
child: CircularProgressIndicator(
strokeWidth: 1,
),
) : Stack(),
],
),
),
);
}
}
That page is supposed to be displayed after I click a button on previous page (homepage).
Why does it not show up ?
Solution 1:[1]
I think you did not give internet permission in android/app/src/main/AndroidManifest.xml
add this line into the <manifest of android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
and more information for insecure http you can see this
<uses-permission android:name="android.permission.INTERNET" /> //This line add
<application
android:name="io.demo.app.test"
android:label="ProjectName"
android:usesCleartextTraffic="true" //This line add
android:icon="@mipmap/ic_launcher">
Solution 2:[2]
Did you appropriately set the WebView.platform = SurfaceAndroidWebView() during the void initState(){} ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gunjon Roy |
| Solution 2 | Klaus Wong |
