From 71beee3a4f87e97e28917b4a081c0a09b0504b32 Mon Sep 17 00:00:00 2001 From: Debashish Kundu Date: Mon, 2 Sep 2024 20:33:30 +0530 Subject: [PATCH] migrate from state to stateflow in ViewModel --- .../template/presentation/viewmodel/HomeViewModel.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/debk007/template/presentation/viewmodel/HomeViewModel.kt b/app/src/main/java/com/debk007/template/presentation/viewmodel/HomeViewModel.kt index 4b2a562..20f7797 100644 --- a/app/src/main/java/com/debk007/template/presentation/viewmodel/HomeViewModel.kt +++ b/app/src/main/java/com/debk007/template/presentation/viewmodel/HomeViewModel.kt @@ -1,8 +1,5 @@ package com.debk007.template.presentation.viewmodel -import androidx.compose.runtime.MutableState -import androidx.compose.runtime.State -import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.debk007.template.model.ProductDetailsDto @@ -10,6 +7,8 @@ import com.debk007.template.repository.Repository import com.debk007.template.util.ApiState import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import javax.inject.Inject @@ -19,9 +18,9 @@ class HomeViewModel @Inject constructor( ) : ViewModel() { // TODO: Set UI State - private val _productDetailsState: MutableState> = - mutableStateOf(ApiState.Loading) - val productDetailsState: State> get() = _productDetailsState + private val _productDetailsState: MutableStateFlow> = + MutableStateFlow(ApiState.Loading) + val productDetailsState = _productDetailsState.asStateFlow() init { getProductDetails()