Closed
Description
Hi,
When trying to implement a floating SliverAppBar
in conjunction with a WebView
Flutter drops a significant amount of frames.
It seems like the WebView is resizing itself whenever the SliverAppBar
is scrolled out of view.
@override
Widget build(BuildContext context) {
return CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: const Text("Heading"),
floating: true,
),
SliverFillRemaining(
child: WebView(initialUrl: "http://stackoverflow.com"),
)
],
);
}
As seen on this GIF:
Metadata
Metadata
Assignees
Labels
High-priority issues at the top of the work listRepeatedly frustrating issues with non-experimental functionalityEmbedding Android/iOS views in Flutter appsRelates to speed or footprint issues (see "perf:" labels)flutter/engine repository. See also e: labels.Found to occur in 1.20The issue has been confirmed reproducible and is ready to work onThe WebView pluginflutter/packages repository. See also p: labels.A fix is in flight
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
Sun3 commentedon Apr 18, 2019
I also have the same issue. But for me the full page article is not shown and gets cut off especially if you reload the page.
dcov commentedon Apr 18, 2019
Yup that's exactly what's happening.
SliverFillRemaining
uses theremainingPaintExtent
constraint, which is the extent that's yet to be painted on, to size its child. This changes as you scroll, which causes theAndroidView
/WebView
to resize as you noticed.SliverFillViewport
is what you're looking for. Although it still doesn't solve your problem of nested scrolling, which I don't think is possible as of now.Sun3 commentedon Apr 19, 2019
I just tested with the
SliverFillViewport
and like you the end result is the same. No difference with theSliverFillRemaining
. Short pages show up but longer pages they get cut off.Reekoooo commentedon Apr 19, 2019
partial solution in my repo
I will share my view here repeating what I wrote in my answer in stackoverflow may be it can help providing a solution
I can give you my view for why it is not possible to do that with the current state of the plugin ,by default the Webview only respond to drag gesture when no other views claim that gesture. On the other hand, Scrolling slivers like SliverList, which is needed to make the SliverAppBar to scroll up ,by default consumes all drag scrolling gestures -although you can disable that by providing noScrollPhysics - but once the WebView cover all the screen there is actually noway to report back to the slivers to start consume scroll again .
So the solution is to modify the WebView plugin itself to provide a callback
I already did that just for a proof of concept you can check my repo Plugins by adding a new callback to the webView
it will report back the ScrollY position which you can use to control your nested scroll
just to make it clear it works only for android api M or above right now
lizhuoyuan commentedon May 17, 2019
the same issue.
I first get the html tag according to the url, then use flutter_html to load the obtained content.
do4Mother commentedon May 28, 2019
Same issues in here. I try 3 plugin webview. But can't use sliverappbar. My app cant scroll.
phoenixsky commentedon Aug 13, 2019
same issue + 1
conghaonet commentedon Aug 15, 2019
same issue:NestedScrollView + SliverAppBar + WebView
stevemoreau commentedon Sep 5, 2019
To anyone following this issue, I'm getting into this, and will try to add some more information in a near future (hopefully, if I could understand it).
Meantime, the pending POC commit of @Reekoooo (see above) : Reekoooo/plugins@666b35f
Gesture arena of a valid use case
Standard AppBar (fixed) + Tabview with 5 tabs (so horizontal scrolling possible)
OUTPUT BEHAVIOR: The WebView allows scroll from the start to the end of the HTML
Gesture arena of a invalid use case (partial HTML, then cut or infinite height)
Scaffold with SliverAppBar + Webview without EagerGestureRecognizer in
gestureRecognizers
propertyOUTPUT BEHAVIOR: SliverAppBar correctly shrinked on scroll global scroll, but partial webview scroll (HTML wrapped to the height of the screen, and the WebView does not allow scroll from the start to the end of the HTML)
Scroll on SliverAppBar area from a screen with Webview using a
EagerGestureRecognizer
in gestureRecognizer propertyScroll on the webview area from a screen with Webview using a
EagerGestureRecognizer
in gestureRecognizer propertyScroll wherever in the screen (SliverAppBar or body) from a screen with SliverGrid
Next things to investigate for me
VerticalDragGestureRecognizer
and arena election process, andSliverList
internals to check how it can properly scroll its own view and let the scroll to be handle by theVerticalDragGestureRecognizer
which (I currently think) is the top gesture handler for Sliver based layouts.Please advise if it is not the right approach.
stevemoreau commentedon Sep 5, 2019
By the way, I've had NestedScrollView + SliverAppBar + WebView previously, and I recently moved to CustomScrollView + SliverAppBar + WebView because it would crash in release builds only.
Please see #30247 (comment) for more information
liyuqian commentedon Sep 30, 2019
@iskakaushik, @amirh : is this also a known performance issue that will be solved once the thread-merging work is done for the WebView?
54 remaining items
blasten commentedon Oct 14, 2020
This has been fixed in Flutter 1.22/ WebView 1.0 - use hybrid composition in the Flutter WebView plugin.
https://github.com/flutter/plugins/tree/master/packages/webview_flutter#using-hybrid-composition
hanniiel commentedon Oct 18, 2020
@blasten
I'm trying to implement CustomScrollView with SliverAppBar. I'm using SurfaceAndroidWebView the header scrolls with the webview that works just fine but when the header is collapsed the scroll doesn't scroll over the webview content and as a result the full webview content isn't visible.
before this update I achieved this functionality by injecting some js into the webview content to detect the scroll direction into the html content and by listening if the body top was visible then I changed the gestureRecognizers according to those events(exmaple:https://www.facebook.com/1792131602/videos/10213309766977319/ ) but It seems this update doesn't fix that or am I missing something?
best regards
@override void initState() { super.initState(); if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView(); } return CustomScrollView( slivers: <Widget>[ SliverAppBar( primary: false, title: const Text("Heading"), floating: true, toolbarHeight: 200, flexibleSpace: FlexibleSpaceBar(), ), SliverFillRemaining( child: WebView( initialUrl: "https://soompi.com", javascriptMode: JavascriptMode.unrestricted, ), ) ], )
using:
webview_flutter 1.0.3
Flutter 1.22.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 84f3d28 (3 days ago) • 2020-10-15 16:26:19 -0700
Engine • revision b8752bb
Tools • Dart 2.10.2
heshaShawky commentedon Nov 12, 2020
Still the issue not fixed!! using Flutter 1.22.3 and flutter_webview 1.0.7 with enabling the Hybrid Composition on every layout possible:
CustomScrollView
withSliverAppBar
andSliverFillRemaining
NestedScrollView
withheaderSliverBuilder
.The current behavior: is scrolling only the app bar height and stop scrolling in the webpage after!!
PerLycke commentedon Nov 25, 2020
@blasten When you say fixed, more specifically what is fixed? In 1.22.4, with hybrid composition, you cannot use a CustomScrollView with a SliverAppBar and then a SliverFillRemaining with a webview. The webview just won't scroll
heshaShawky commentedon Dec 13, 2020
This bug indeed still exists and not fixed yet!! I can't scroll on the webview itself and the sliverappbar even is glitchy, that in the latest version on flutter 1.22.4
edisonywh commentedon Feb 14, 2021
Hey team, any update on this or should we create another issue to track this? I tried it out with the new Hybrid Composition awhile back and that didn't seem to work. There is a new issue at #72888 but I believe that's a different issue.
The original problem as reported in this issue is to have a SliverAppBar + a WebView, and that scrolling on the WebView should collapse the SliverAppBar. The code example and a GIF that accompanies it describes it pretty well.
blasten commentedon Feb 22, 2021
This issue is about the scroll performance while having (a) a platform view and (b) a
SilverAppBar
. This issue was closed because hybrid composition did solve the root cause to the issue, which is the performance of resizing the webview.I hear that it would be useful to have an example that deals with other issues:
I'd love to hear if any of you would be interested in sending a PR to the WebView plugin example app that accomplishes exactly this. Some ideas about how to approach it:
WebViewController#evaluateJavascript
(For example) to get theheight
of the HTML document. e.g.document.scrollingElement.scrollHeight
.SizedBox
as a child ofSliverFillRemaining
, and set the height to the value you received from the JS controller.emvaized commentedon Jun 30, 2021
I guess the best solution I came up with for now is:
Here is quick snippet for illustration: https://gist.github.com/emvaized/fa1ce586109196d7357652de2843b8ff
However, it has issues — for example app bar jumps back and forth when finger movement is very slow. Also animation is choppy sometimes.
But at least, for now this approach seems to work
github-actions commentedon Jul 30, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -v
and a minimal reproduction of the issue.