0

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 ?

Ray
  • 31
  • 5

2 Answers2

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">
Gunjon Roy
  • 139
  • 1
  • 8
0

Did you appropriately set the WebView.platform = SurfaceAndroidWebView() during the void initState(){} ?

Klaus Wong
  • 59
  • 2
  • No, but now it's solved, I only update the flutter and dependencies (because there's an update available as soon as this issue posted), and everything goes well ... – Ray Oct 06 '21 at 10:24
  • Geat maybe previous vision because of the dependencies conflict between the flutter and native. – Klaus Wong Oct 06 '21 at 11:14