1

I am having trouble launching new screen widget. I have main.dart where I am using bottomNavigationBar and body for ViewPager UI. Now I have 3 bottom tabs and when I go to 2nd tab's view and click on a button to launch another screen/view using:

onTap: () => Navigator.of(context).push(
                 MaterialPageRoute(
                     builder: (context) => ViewMyContactList(),
                 ),
            )

the new screen replaces the 2nd tab's view, when I go to 3rd tab then come back to 2nd tab, the new screen is gone and 2nd tab's initial screen is back. Also when new screen replaces the 2nd screen's initial view and when I do system back press in Android, the app exits straightaway.

rohitpaniker
  • 695
  • 1
  • 7
  • 25
  • When you switch tabs the tab is unloaded from ram. When you switch back Its being rebuilt that is why it's loading again the default tab. You will need to keep track of the change and load the correct thing. – Kent Dec 01 '19 at 09:52
  • Or change the behavior to keep it in ram. https://stackoverflow.com/questions/51224420/flutter-switching-to-tab-reloads-widgets-and-runs-futurebuilder – Kent Dec 01 '19 at 09:55

1 Answers1

0

You are trying to do Multiple Navigators with BottomNavigationBar
You can reference this doc for detail https://medium.com/coding-with-flutter/flutter-case-study-multiple-navigators-with-bottomnavigationbar-90eb6caa6dbf

Each tab must keep it'own Page Route, you can use the demo code in doc or
You can use the following two package to help you

https://pub.dev/packages/multi_navigator_bottom_bar
Helps you to build multi-navigator bottom navigation bar more easily.

https://pub.dev/packages/nested_navigators Flutter widget for implementing multiple nested navigators with their own route stacks.

chunhunghan
  • 51,087
  • 5
  • 102
  • 120