I am using Webview_Flutter. The header of the site overlaps the position of the statusbar and I would like to add padding to avoid this.
This is the process of inserting padding to avoid the statusbar if the webview is opened or if there is a scroll position at the top.
body: Padding(
padding: (controller?.getScrollY() == null || controller?.getScrollY() == 0)
? EdgeInsets.only(top: height)
: EdgeInsets.only(top: 0),
child: Expanded(
child: Padding(
padding: const EdgeInsets.only(bottom: 0.0),
child: WebView(
javascriptMode: JavascriptMode.unrestricted,
initialUrl: Uri.parse(widget.link).toString(),
onWebResourceError: (error) {
// print(error.domain);
},
onWebViewCreated: (controller) {
this.controller = controller;
},
onProgress: (progress) {
setState(() {
this.progress = progress / 100;
progressPercent = progress;
});
},
),
To detect WebView scroll event, you can use the
flutter_inappwebviewplugin (I'm the author) and implement theInAppWebView.onScrollChangedevent.However, probably you don't need to add top padding for your WebView. You can set the
AppBar.toolbarHeightto0, so the app bar will have the right height to cover the status bar.Here is a full code example with both cases using the current latest version 6 available of the plugin (
6.0.0-beta.16):