well nothing really interesting 😄
basically, here is a sample viewmodel :
@HiltViewModel
class MyViewModel @Inject constructor(
private val savedStateHandle: SavedStateHandle
) : ViewModel() {
val someItemId: StateFlow<Long> = savedStateHandle.getStateFlow(ItemIdArg, -1L)
/**
* Some State
*/
var someState: SomeState by mutableStateOf(SomeState())
private set
/**
* Some state for the UI
*/
var someSavedState: SomeState by savedStateHandle.saveable(key = "SomeState", stateSaver = SomeState.Saver, init = {
mutableStateOf(
SomeState()
)
})
private set
}
We can expose the state either through
mutableStateOf
directly, or use the new
saveable
api to get it saved in the `SavedStateHandle`/`rememberSaveable`
now my Screen receive an arg through Navigation, let’s say a `detailId`;
You can get this arg using simply
handle.getStateFlow(ArgKey)
and I was wondering if there was a similar helper that returns a Compose
State<>
/
MutableState<>
(so we can use it directly from a
Composable
, or use it in the
ViewModel
, the same as the
SomeState
I have)