Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView without height inside Scroll not working

On Flutter...I tried to add Webview inside all the available containers that support scroll but it didn't work on Android.

ListView(
          shrinkWrap: true,
          children: <Widget>[
            Text("hiiiiiiiiiiiii "),
            Text("hiiiiiiiiiiiii "),
            Text("hiiiiiiiiiiiii "),
           Expanded(
                child: WebView(
                    key: Key("webview1"),
                    debuggingEnabled:  true,
                    javascriptMode: JavascriptMode.unrestricted,
                    initialUrl: "https://flutter.dev/")),
            Text("hiiiiiiiiiiiii "),
            Text("hiiiiiiiiiiiii "),
            Text("hiiiiiiiiiiiii "),
          ],
)
like image 909
BeshoyAdel Avatar asked Apr 19 '26 18:04

BeshoyAdel


1 Answers

If you want to put your scrollable WebView between other widget's and WebView will be scrollable, other's widget's are not, then just change your ListView for Column like that:

Column(
  children: <Widget>[
    Text("hiiiiiiiiiiiii "),
    Text("hiiiiiiiiiiiii "),
    Container(
      height: 300,
      child: WebView(
          key: Key("webview1"),
          debuggingEnabled: true,
          javascriptMode: JavascriptMode.unrestricted,
          initialUrl: "https://flutter.dev/")
    ),
    Text("hiiiiiiiiiiiii "),
    Text("hiiiiiiiiiiiii "),
)

But if u want to have some scrollable widgets on top of WebView, then try CustomScrollView or SliverList.

Can you tell what exact logic you are trying to make?

additions:

If you want to have scrollable area and some WebView inside, you can have to know height of WebView:

ListView(
  physics: ClampingScrollPhysics(),
  children: <Widget>[
    Text("hiiiiiiiiiiiii "),
    Text("hiiiiiiiiiiiii "),
    ConstrainedBox(
      constraints: BoxConstraints(maxHeight: 10000),
        child: WebView(
          gestureRecognizers: Set()
            ..add(
              Factory<VerticalDragGestureRecognizer>(
                  () => VerticalDragGestureRecognizer(),
              ), // or null
            ),
            key: Key("webview1"),
            debuggingEnabled: true,
            javascriptMode: JavascriptMode.unrestricted,
            initialUrl: "https://flutter.dev/")),
    Text("hiiiiiiiiiiiii "),
    Text("hiiiiiiiiiiiii "),
  ],
);

Height of WebView you could get dynamically, inspiration is here: https://gist.github.com/PonnamKarthik/877a90917a576ecff613d5169680d02c

like image 154
dubace Avatar answered Apr 22 '26 08:04

dubace



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!