I have a page in Flutter which has 3 different elements header, sidebar and main_content. Sidebar contains some text buttons login, customer, manager etc.
When someone clicks on the button on the sidebar i want to change only the content of the main_content. I dont want to replace whole screen. I just want to replace the content of main_content with another widget.
I am not sure if it can be done using flutter package go_router. Or I have to use state management for this case.
I tried Go_router shell routes. But i think it is made for different purpose.
2
Answers
This can be achieved with shellRoutes in go_router. But if you just want to change the content of the page, then you can follow this approach:
Following my suggestion, you would initialize a variable named
_currentMainContent
with a type ofWidget
, setting it initially to aPlaceholder
widget. This variable would represent the main content area of your application.Whenever a user interacts with a side menu item, you would update the
_currentMainContent
variable to display the appropriate widget corresponding to the selected menu item. This approach allows for dynamic content switching within the main content area of your application.