I am trying to create a screen that has a WebView (from webview_flutter: ^0.3.5+3) and an AppBar
that I want to scroll offscreen on user scroll.
I stumbled upon this guide and tried implementing something similar, but no dice.
Is there a way to use a WebView
in a CustomScrollView
with Slivers
or is this not supported yet?
I can get the scrolling app bar to work if I create regular Widgets in my SliverChildListDelegate
(I tried Row
, Text
, Container
etc.), but had no luck with a WebView
.
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: const Text("Heading"),
floating: true,
),
SliverList(
delegate: SliverChildListDelegate([
Container(
child: WebView(
initialUrl: url,
javascriptMode: JavascriptMode.unrestricted,
),
)
]
),
)
],
)
);
}
Any pointers/suggestions/RTFMs welcome.
EDIT BOUNTY
The solution provided by jordan-davies works but is very choppy.
Whenever the SliverAppBar
is scrolled away the WebView
tries to resize itself to fill the remaining viewport. This makes for a very choppy/slow experience.
@override
Widget build(BuildContext context) {
return CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: const Text("Heading"),
floating: true,
),
SliverFillRemaining(
child: WebView(initialUrl: "http://stackoverflow.com"),
)
],
);
}