3

I am making a simple screen containing a WebView encapsulated inside a Scaffold. There is a button above the WebView. The WebView is not loading the page. However, when the WebView is not encapsulated inside the Scaffold, the page loads. I need to have the Scaffold as a container to add other widgets. How to make the WebView loads its page inside the Scaffold.

Codes containing WebView inside Scaffold. WebView does not load

return MaterialApp(
      home: Scaffold(
          body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
            children: [
              TextButton(
                onPressed: () {
                 
                },
                child: Text('Print page'),
              ),
              WebView(
                initialUrl: 'https://flutter.dev',
              )
          ],),),
    );

Codes containing only WebView. WebView does not load

   return MaterialApp(
      home: WebView(
        initialUrl: 'https://flutter.dev',
      ),
    );
1
  • if you are using the Flutter community Plugin of Webview. Then you need to use WebViewScaffold. Please check this medium link medium.com/@zeyadelosherey/… Commented Oct 15, 2021 at 7:20

2 Answers 2

8

This code work for me. Try this out

return Scaffold(
  appBar: AppBar(
    title: Text('test'),
  ),
  body: Column(
    children: [
      RaisedButton(
        onPressed: () {},
        child: Text('Test'),
      ),
      Expanded(
        child: WebView(
          initialUrl: 'https://flutter.dev',
          javascriptMode: JavascriptMode.unrestricted,
        ),
      ),
   
    ],
  ),
);

Cheack the screenshot

Sign up to request clarification or add additional context in comments.

1 Comment

this is the only solution worked for me. instead of RaisedButton use SizedBox() for better experience
6
******Give Internet Permission in Android Manifest.xml file and the permission is below

https://stackoverflow.com/questions/55603979/why-cant-a-flutter-application-connect-to-the-internet-when-installing-app-rel


<manifest xmlns:android="...">
  <uses-permission android:name="android.permission.INTERNET"/>
</manifast>

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.