A ViewModel is needed to save the app's transient data and to also access the database.
ViewModel interacts with the database via the DAO, and provides data to the UI. All database operations will have to be run away from the main UI thread, you'll do that using coroutines and viewModelScope.
The DAO object is needed as a parameter to the default constructor.
The ViewModelFactory class with the same constructor parameters is needed to instantiate the ViewModel. In this example The overriden createMethod checks if the modelClass is the same as InventoryViewModel class.
The ViewModelFactory is mostly boilerplate code, so can be used without getting into the details in most cases. Yet I still need to learn more about the Factories 😅
Notice that you did not use viewModelScope.launch for addNewItem(), but it is needed above in insertItem() when you call a DAO method. The reason is that the suspend are only allowed to be called from a coroutine or another suspend function. The function itemDao.insert(item)is a suspend function.