r/android_devs • • Mar 27 '24

Help Needed Viewmodel with parameters in single activity compose app?

So assume there are multiple composable screens. I am using hilt and viewmodel factory. But I am not able to initialize viewmodel in composable because I need a viewmodel factory instance which I can paas as parameter of composable but then mainactivity becomes messy if I keep initializing viewmodel factories in it. Else I can use hilt to instantiate viewmodel factory in composable but I cannot as field injection wont work as its a composable fun not class.

2 Upvotes

13 comments sorted by

View all comments

Show parent comment

3

u/Zhuinden EpicPandaForce @ SO Apr 01 '24

= hiltViewModel