Last active
March 2, 2022 10:12
-
-
Save cp-hardik-p/8c34dce90cbdbf890cb1babd14067bff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltViewModel | |
class MainViewModel @Inject constructor(private val apiService: ApiService) : ViewModel() { | |
var movieListResponse: List<Movie> by mutableStateOf(listOf()) | |
var errorMessage: String by mutableStateOf("") | |
fun getMovieList() { | |
viewModelScope.launch { | |
try { | |
val movieList = apiService.getMovies() | |
movieListResponse = movieList | |
} catch (e: Exception) { | |
errorMessage = e.message.toString() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment