So I have recently started my first project in flutter, I completed the full UI layout and am now doing the whole logic part of the front-end, most of my onTap behavior is working, but I have come to the following situation I do not know how to tackle.
I have four files which contains all the UI.
widget0.dart
widget1.dart
widget2.dart
These files each hold the StatefullWidget which are being build by the BottomNavigationBar.
main.dart
This file contains my main() =>runApp class and function. My MaterialApp contains a Scaffold with a BottomNavigationBar. This works as intended and I am being able to switch between each of the 3 widgets.
However in my widget0.dart file I have a button which should change the index of the BottomNavigationBar from my main.dart file from 0 to 2 (to build the widget from widget2.dart).
I have tried to wrap up the value that holds the index for the navigation bar in a separate static class, so I could setState((){ StaticClass.index = 2})
in the button onTap(), but this doesn't work, and actually freezes the navigation bar to its initial value.
An answer somewhere here on stackoverflow suggested that each of the Widgets should have it's own Scaffold and navigationbar, however I am sure there must be a cleaner way.
So what is the most Fluttery way to achieve my goal?
Thanks in advance.