ListLab.kt
  1. 1class LessonViewModel(
  2. 2 private val repo: LessonRepository,
  3. 3) : ViewModel() {
  4. 4 private val _load = MutableStateFlow<Load<List<Lesson>>>(Load.Loading)
  5. 5 val load: StateFlow<Load<List<Lesson>>> = _load
  6. 6
  7. 7 init {
  8. 8 viewModelScope.launch {
  9. 9 _load.value = Load.Ready(repo.all())
  10. 10 }
  11. 11 }
  12. 12}

A list that does not freeze the first frame

The first composition paints a loading state. The read happens in a coroutine.

Danville · educational · 2018AboutDeskFAQOffice