I'm developing an app in flutter, and i got stuck while trying to preload a page in webview. Basically, the app uses tabbar, with a few tabs with normal listview content in them, and 2 tabs that should have webview as content. Any idea how to preload the webviews and keep them alive in background while the app loads, so when the user swipes between tabs, and gets on the webview ones, the sites are already loaded and rendered so the UX is seamless. I have tried creating the WebView instance and assigning it to a variable using setstate on app load, but to no avail.
Any help would be appreciated.
Introduction. With the WebView Flutter plugin you can add a WebView widget to your Android or iOS Flutter app. On iOS the WebView widget is backed by a WKWebView, while on Android the WebView widget is backed by a WebView. The plugin can render Flutter widgets over the web view.
So what you can try doing is this:
Wrap the widgets you are calling in your TabBar with a PageView like shown here.
You can also ensure that the WebView stays alive after loading once by extending your stateful widget with AutomaticKeepAliveClientMixin
. While using this ensure that you declare:
bool get wantKeepAlive => true;
Edit: In order to preload all your pages when your app launches you can use Indexed Stack in the class your TabBar is declared. Wrap the body and call all the pages there like this:
Widget build(BuildContext context) {
return
Scaffold(
body:IndexedStack(
index: _selectedIndex,
children: _children,
),),}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With