Search code examples
flutterdartwebviewreload

Flutter Webview reloads every time I switch screen


I'm making an app with a BottomNavigationBar with 5 different screens, each of them has a web view. The problem is that everytime I come back to a screen that was previously loaded, it reloads. I have tried using AutomaticKeepAliveClient from copy pasting this code but I doesn't seem to work. I'm new with Flutter so be precise please, thank you.


Solution

  • AutomaticKeepAliveClient is mainly used for keeping a child alive in lazily rendered list views. In your case whenever you switch tabs your current page get disposed and new page materializes on top of it, that means each time when you switch tab a new page is created including all it's widgets.

    So if you want to keep your previously loaded web views alive, you have to go with either PageView widget or use Stack widget to load your pages programmatically while the user clicks on a tab.

    This is a detailed example about implementing your requirement using PageView widget . you can also find an example with Stack widget under that question.