hi all, have the feeling im doing something a bit ...
# compose
a
hi all, have the feeling im doing something a bit backwards wrt handling events.
Copy code
LaunchedEffect(key1 = event) {
        when (event) {
            ManualPaymentEvent.LoadingError -> {
                scaffoldState.snackbarHostState.showSnackbar(
                    message = snackbarMessage,
                    actionLabel = snackbarAction,
                    duration = SnackbarDuration.Indefinite
                )
                viewModel.onSnackBarDismissClicked()
            }
            ManualPaymentEvent.NavigateBack ->
                navigateUp()
            is ManualPaymentEvent.NavigateWithCards ->
                navigateToSelectCard(event.amount, event.cards)

            is ManualPaymentEvent.NavigateWithoutCards ->
                navigateToAddCard(event.amount)

            null -> Unit
        }
        viewModel.eventConsumed()
    }
viewModel.eventConsumed()
sets the event to null again, to show it has been consumed.
onSnackbarDismissClicked
updates the uiState with
uiState = uiState.copy(event = ManualPaymentEvent.NavigateBack)
. the intent here is that the NavigateBack event triggers the
navigateUp()
function but this never happens. The issue appears to be that the event is first set to NavigateBack. then before this LaunchedEvent can trigger, the event is first set to null, and this NavigateBack event is ignored. What should i be doing? would this be resolved if i was holding my state in a Flow of some kind?
the other option is to separate these events. i have the habit of sticking all events into one variable back from the days of LiveData but this may not be the way to go