Hi. I am trying to implement a screen with multipl...
# compose
p
Hi. I am trying to implement a screen with multiple tabs (accompanist - pager) so i did something like this:
Copy code
@Composable
fun Screen() {
  val screenViewModel: ScreenViewModel = hiltViewModel()
  val pages by screenViewModel.pages.collectAsState()
  val pagerState = rememberPagerState(pageCount = pages.size)

  HorizontalPager(state = pagerState) { index ->
    Column(modifier = Modifier.fillMaxWidth()) {
      // this viewmodel should be created with data from the page object (e.g. id)
      val pagerViewModel: PagerViewModel = hiltViewModel() // actual: same viewmodel on every page -> expected: every page get´s its own viewmodel
      ...
    }
  }
}
Is it possible to get a ViewModel per page via hilt or should i use a complete different approach than ViewModels in this case?
b
I came across the same question. did you find a solution for this?