6

I have a Scaffold like this:

Scaffold(
   topBar = {
       TopBar(...)
   },
   bottomBar = {
       BottomNavigationBar(...)
   }
) {
    NavHost(...)
}

What is the best way to change TopBar when I navigate to another screen?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Hieu Le
  • 61
  • 2

1 Answers1

2

There are two possible ways to go:

  1. Observing currentScreen and use when inside topBar and change it according to that

  2. Put topbar inside the screen it belongs to.

For me prefer the second one since it's not shared with each other, there's no reason to use ugly when statement for it.

adwardwo1f
  • 817
  • 6
  • 18
  • For (2), should I put `Scaffold()` inside each screen? Or, I can use single `Scaffold()`, but create a mutable state of composable function (the content of top bar), pass that state to and set it from each screen? – xierch Oct 06 '21 at 13:43
  • 1
    @xierch yes, put `Scaffold()` inside each screen. What u just said is (1) `currentScreen ` which is `mutableState` with a single `Scaffold()` – adwardwo1f Oct 07 '21 at 09:20
  • 1
    Since I use BottomAppBar I already have a scaffold on my main screen, can I nest another scaffold inside the main scaffold to manage the TopAppBar according to the sub screen where I am, or there are some problems doing this? – TheFedex87 Jun 24 '22 at 16:37