ItemViewModel

class ItemViewModel @Inject constructor(homeRepository: HomeRepository, savedStateHandle: SavedStateHandle) : ViewModel

ViewModel for the create/edit item screen, managing Jetpack library creation and updates.

This ViewModel handles both creating new Jetpack items and editing existing ones. It uses SavedStateHandle to retrieve the optional item ID from navigation arguments. If an ID is present, the screen operates in edit mode; otherwise, it creates a new item with a generated UUID.

The ViewModel demonstrates:

Parameters

homeRepository

Repository providing Jetpack data operations.

savedStateHandle

Navigation state containing optional item ID from route.

See also

Immutable data class representing form state

State wrapper with loading and error handling

Extension function for synchronous state updates

Extension function for async operations with state updates

Ensures navigation events are consumed only once

Data layer interface for home screen operations

Constructors

Link copied to clipboard
@Inject
constructor(homeRepository: HomeRepository, savedStateHandle: SavedStateHandle)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open fun addCloseable(closeable: AutoCloseable)
fun addCloseable(key: String, closeable: AutoCloseable)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun updateName(name: String)
Link copied to clipboard
fun updatePrice(priceString: String)