Samuel
11/20/2024, 6:04 PMFATAL EXCEPTION: main
Process: dev.upvote.debug, PID: 22296
There's no other traceback; I've tried running with debugger also.Pablichjenkov
11/20/2024, 6:09 PMGabe Kauffman
11/20/2024, 7:30 PMPablichjenkov
11/20/2024, 7:56 PMPablichjenkov
11/20/2024, 7:56 PMSamuel
11/20/2024, 8:57 PMSamuel
11/21/2024, 7:32 PMPablichjenkov
11/21/2024, 7:34 PMGabe Kauffman
11/21/2024, 7:37 PMSamuel
11/21/2024, 7:39 PMviewModel.getProfile()
line. When that's removed it doesn't crash. But there's nothing fancy going on there; so a bit confused.Gabe Kauffman
11/21/2024, 7:44 PMgetProfile()
to narrow down exactly what's going wrong there.
In general having lifecycle listeners in Composables strikes me as a weird and potentially dangerous pattern
OnLifecycleEvent { _, event ->
when (event) {
Lifecycle.Event.ON_RESUME -> {
viewModel.getProfile()
}
else -> {}
}
}
Pablichjenkov
11/21/2024, 7:49 PMGabe Kauffman
11/21/2024, 7:54 PMval profile = profileContentRepository.getProfile().first()
profile.also {
setProfile(profile = profile!!)
}
• .first() will cause a crash if the flow does not have a value, prefer to use .firstOrNull()
• profile!!
will cause a crash if profile
is null, prefer to do something like
profile?.let {
setProfile(profile = it)
}
Samuel
11/21/2024, 8:37 PMIn general having lifecycle listeners in Composables strikes me as a weird and potentially dangerous patternAgreed, only added them as a debug measure Oh I thought
profile.also
did that. Ok changed to your syntax.
As for first
, it's
override fun getProfile() = flow {
emit(profileApi.getProfile())
}
Where profileApi.getProfile
is either going to error [404] or have one value [.first
guaranteed to succeed]