Using Kotlin Flow in MVVM
summary
Shows replacing LiveData and suspend calls with Kotlin Flow using a fake repo that emits loading then a 1s-delayed random result, and a separate while(true) stream emitting once per second to simulate real-time updates. Demonstrates converting Flow to UI with asLiveData or collecting directly with lifecycleScope.launchWhenStarted / repeatOnLifecycle, uses operators like map/filter/onEach/flowOn/catch, and tests flows with runBlocking, collectIndexed/toList and a TestCoroutineDispatcher replacing Dispatchers.Main so unit tests run deterministically.
AI-written summary · about
chapters (9)
- 0:00Introduction
- 2:54LiveData in MVVM
- 6:45Flow basics and advantages
- 8:11Flow with LiveData
- 10:41Real-time data streams
- 11:03Flow operators overview
- 14:34LiveData vs Flow
- 15:36Using Flow alone
- 18:04Testing Flow








