Javier
02/11/2023, 9:34 PMMoleculeViewModel
sample.
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "....DataSource.getFlow()" because "this.datasource" is null
class PupperPicsViewModel(private val datasource: Datasource) : MoleculeViewModel<Event, Model>() {
@Composable
override fun models(events: Flow<Event>): Model {
val data by datasource.flow.collectAsState()
return PupperPicsPresenter(events, PupperPicsService())
}
}
kevin.cianfarini
02/11/2023, 10:03 PMremember
the call to datasource.flow?Javier
02/11/2023, 10:28 PMComposable calls are not allowed inside the calculation parameter of inline fun <T> remember(calculation: () -> TypeVariable(T)): TypeVariable(T)
Javier
02/11/2023, 10:28 PM@Composable
fun <T> produceState(
initialValue: T,
key1: Any?,
key2: Any?,
@BuilderInference producer: suspend ProduceStateScope<T>.() -> Unit
): State<T> {
val result = remember { mutableStateOf(initialValue) }
LaunchedEffect(key1, key2) {
ProduceStateScopeImpl(result, coroutineContext).producer()
}
return result
}
Javier
02/11/2023, 10:31 PMremember { datasource }
fails too, with the null crashJavier
02/11/2023, 10:33 PMhfhbd
02/11/2023, 11:01 PMJavier
02/11/2023, 11:09 PMJavier
02/11/2023, 11:09 PMJavier
02/11/2023, 11:09 PMFooStore
= PupperPicsViewModel
in the previous code