updateState

inline fun <T : Any> MutableStateFlow<UiState<T>>.updateState(update: T.() -> T)

Updates the UI state synchronously without showing loading indicators or handling errors.

Use this function for immediate, synchronous state updates such as:

  • Text input changes

  • UI toggle states

  • Local UI state modifications

  • Navigation state updates

This function does NOT:

  • Set loading state

  • Handle exceptions

  • Run in a coroutine scope

Usage Example

@HiltViewModel
class ProfileViewModel @Inject constructor() : ViewModel() {
private val _uiState = MutableStateFlow(UiState(ProfileScreenData()))
val uiState = _uiState.asStateFlow()

fun updateName(name: String) {
_uiState.updateState {
copy(name = name)
}
}
}

Parameters

T

The type of the screen data.

update

Lambda that receives current data and returns updated data. Use data class copy() to create the new state.

See also

for async operations that return new data

for async operations that return Unit

Samples

dev.atick.feature.auth.ui.signin.SignInViewModel.updateEmaildev.atick.feature.auth.ui.signin.SignInViewModel.updatePassword