Skip to content

Instantly share code, notes, and snippets.

@cp-hardik-p
Last active March 2, 2022 10:12
Show Gist options
  • Save cp-hardik-p/8c34dce90cbdbf890cb1babd14067bff to your computer and use it in GitHub Desktop.
Save cp-hardik-p/8c34dce90cbdbf890cb1babd14067bff to your computer and use it in GitHub Desktop.
@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