How to Save Tabs States in BottomNavigationBar in Flutter

Neat Snippets · 5K views · 2020 · 4:46

Open on YouTube

Software (other)Web developmenttutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering how to preserve widget state across BottomNavigationBar tabs in Flutter.

Recommended by 2 people across 2 different months, 2020 to 2022.

What it is

A short Flutter tutorial from the Neat Snippets channel showing how to keep each tab's state alive when switching pages in a BottomNavigationBar. It uses a PageView together with AutomaticKeepAliveClientMixin, with the full code available on GitHub.

What people said

Recommends Tayan · 2020-09 · Stack Overflow · on “How to preserve widget states in flutter, when navigating using BottomNavigationBar?”

Late to the party, but I've got a simple solution. Use the PageView widget with the AutomaticKeepAliveClientMixin . The beauty of it that it doesn't load any tab until you click on it. The page that includes the BottomNavigationBar : var _selectedPageIndex; List<Widget> _pages; PageController _pageController; @override void initState() { super.initState(); _selectedPageIndex = 0; _pages = [ //The individual tabs. ]; _pageController = PageController(initialPage: _selectedPageIndex); } @override void dispose() { _pageController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { ... body: PageView( controller: _pageController, physics: NeverScrollableScrollPhysics(), c

Recommends Mercy · 2022-07 · Stack Overflow · on “Here Maps Navigate restarts Navigation on page change”

I finally found a way to solve it by saving the state of my Flutter pages. I used the PageView widget for the main.dart's scaffold body and AutomaticKeepAliveClientMixin on the pages I wanted to save the states of. You can check this YouTube video for how to implement this: [this video]

Cites Kolompos · 2022-11 · Stack Overflow · on “Flutter and Flame, how to keep FlameGame widget alive?”

Working on a game project where: I have a BottomNavigationBar navigating betwen my custom Widgets where one of them is a FlameGame. I don't want to unload and reload the widgets when player navigates as it will be frequent and expensive. I have followed this [this video] and now my custom Widgets are being preserved, except for the FlameGame. Tried adding AutomaticKeepAliveClientMixin. Wanted me to implement 12 overrides... Any suggestions?