-1
I’m making a logic in my app to present the appBar of it just when I need wing to appear or not.
For this I did the following Viewmodel: Stateappviewmodel
@HiltViewModel
class StateAppViewModel @Inject constructor(
) : ViewModel() {
val components: LiveData<VisualComponents> get() = _components
private var _components: MutableLiveData<VisualComponents> =
MutableLiveData<VisualComponents>().also {
it.value = hasComponents
}
var hasComponents: VisualComponents = VisualComponents()
set(value) {
field = value
_components.value = value
}
}
class VisualComponents(
val appBar: Boolean = false
) ´´´
Na classe que quero que o appBar aparece, eu faço:
```stateAppViewModel.hasComponents = VisualComponents(true)´´´
E na MainActivity verifico:
controller.addOnDestinationChangedListener { _, destination, _ ->
title = destination.label
viewModel.components.observe(this, {
it?.let { hasComponents ->
if (hasComponents.appBar) {
supportActionBar?.show()
} else {
supportActionBar?.hide()
}
}
})
}
Acredito que esteja fazendo algo errado, pois o viewModel não é injetado pelo Hilt.
Alguém poderia me ajudar?
Pasta, thank you very much
– Daniel Lopes