How to dynamically pass parameters in the Android ViewModel?

In the following variables, how do I dynamically pass user.id and friend.id class WindViewModel @Inject constructor() : BaseViewModel() { val userWindList = Pager(config = pagingConfig, remoteMediator = WindRemoteMediator("userWindList", user.id, friend.id, database!!, api)) { windRepository.pagingModelList(friend.id, "userWindList") }.flow.map { pagingData -> pagingData.map { it.json.toWind() } }.cachedIn(viewModelScope) } >Solution : I am assuming you specifically mean how to… Read More How to dynamically pass parameters in the Android ViewModel?

What is the proper way to update list state after inserting an item via a repository in Compose?

I have a Room app which displays a list of presets, and the user has the option of adding them by pressing a ‘New Quick Preset’ button: Code for inserting new item into Room database (in ViewModel): fun insertQuickPreset(quickPreset: QuickPreset) { viewModelScope.launch { repository.insertQuickPreset(quickPreset) } } State: data class NewScreenState( @StringRes val nameError: Int? =… Read More What is the proper way to update list state after inserting an item via a repository in Compose?

How to create a ViewModel object inside composable function correctly?

I have this structure in my MainActivity: val navController = rememberNavController() NavHost( navController = navController, startDestination = ItemsScreen.route ) { composable( route = ItemsScreen.route ) { ItemsScreen( navController = navController ) } composable( route = ItemDetailsScreen.route + "/{itemId}", arguments = mutableStateListOf( navArgument("itemId") { type = NavType.StringType } ) ) { backStackEntry -> val itemId =… Read More How to create a ViewModel object inside composable function correctly?