backStackHostViewModel

inline fun <VM : ViewModel> backStackHostViewModel(viewModelStoreOwner: ViewModelStoreOwner = checkNotNull(backStackHostViewModelStoreOwner()) { "No ViewModelStoreOwner was provided for backStackHostViewModel" }, key: String? = null, factory: ViewModelProvider.Factory? = null, extras: CreationExtras = if (viewModelStoreOwner is HasDefaultViewModelProviderFactory) { viewModelStoreOwner.defaultViewModelCreationExtras } else { CreationExtras.Empty }): VM(source)

Returns a ViewModel using a ViewModelStoreOwner resolved from the back stack host context.

This is useful for obtaining ViewModels that are scoped to the host of the back stack.

Return

An instance of the specified ViewModel.

Parameters

VM

The type of the ViewModel.

viewModelStoreOwner

The ViewModelStoreOwner that will host this ViewModel. Defaults to the current LocalBackStackHostViewModelStoreOwner if available, otherwise falls back to the current LocalViewModelStoreOwner.

key

An optional key to differentiate amongst ViewModels of the same type.

factory

An optional ViewModelProvider.Factory to use for creating the ViewModel.

extras

The CreationExtras to use for creating the ViewModel. Defaults to HasDefaultViewModelProviderFactory.defaultViewModelCreationExtras if the resolved viewModelStoreOwner implements it, otherwise CreationExtras.Empty.