0

How we can change BottomNavigationBar page using Navigator push method without losing each page state?

extra details: that is useful on nested navigation, when we want to use Navigator.of method to access nearest Navigator on widget hierarchy. so we can change tabs from inside a tab content. this situation is also a part of explained scenario on this question Flutter integrated stacked and tabbed navigations.

Siamak S
  • 163
  • 9

1 Answers1

0

Use AutomaticKeepAliveClientMixin . After loading first time page state,there is no need to reload this(mens it's not losing it's old state)

Like this,

class ListWidget extends StatefulWidget { @override 
_ListWidgetState createState() => _ListWidgetState();
    
  } 
    
    class _ListWidgetState extends State<ListWidget> with AutomaticKeepAliveClientMixin<ListWidget>{ // ** here 
    @override
 Widget build(BuildContext context) { return Container(); 
    } 
    @override
     bool get wantKeepAlive => true; 
     }
Shirsh Shukla
  • 5,491
  • 3
  • 31
  • 44