Persisting UI State and Building Bottom Navigation Bars in Dart's Flutter Framework
Why Stack Overflow recommends it
Stack Overflow users link it when answering Flutter questions about bottom navigation bars and tabs that rebuild or lose their state when switching pages.
Recommended by 3 people across 3 different months, 2018 to 2020.
What it is
A roughly 20 minute Flutter tutorial from the Tensor Programming channel that builds a bottom navigation bar and shows how to keep each page's UI state alive using PageStorageKey and PageStorageBucket. The author walks through the code and links the full source on GitHub.
What people said
Recommends Javid Noutash · 2018-06 · Stack Overflow · on “Flutter: Default Tab Bar Controller does not maintain state after swipe”
You need to use PageStorage widget and PageStoageBucket and wrap your page inside a PageStorage widget. Please refer to this tutorial for more details: Persisting UI State and Building Bottom Navigation Bars in Dart's Flutter Framework [this video]
Recommends Daibaku · 2018-10 · Stack Overflow · on “Flutter: BottomNavigationBar rebuilds Page on change of tab”
I'm not sure but CupertinoTabBar would help. If you don't want it, this video would be great url [this video] . import 'dart:async'; import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart'; class HomeScreen extends StatefulWidget { @override _HomeScreenState createState() => new _HomeScreenState(); } class _HomeScreenState extends State<HomeScreen> { final List<dynamic> pages = [ new Page1(), new Page2(), new Page3(), new Page4(), ]; int currentIndex = 0; @override Widget build(BuildContext context) { return new WillPopScope( onWillPop: () async {
Recommends Mitch Q · 2019-09 · Stack Overflow · on “Keep variable value after view change”
Thanks this helped immensely it pointed me in the right direction. This video was also useful in understanding page storage [this video]
Cites Matheus Dias · 2020-04 · Stack Overflow · on “Using BottomNavigation with State and build parameters”
actually, i followed this article, but i found confusing because all the pages are the same, just changed icon, color and name, that is not my case, so i went with this one: [this video]