I am having an error in my apk. After first snackbar shows, whenever I rotate my screen it shows that snackbar again.I don’t want to show any snackbar, whenever my screen rotates. It happens for RegistrationUiState.Error
state.
Could anyone please help me to identify the problem? If you want the full code, please refer to this https://github.com/openMF/mifos-mobile/pull/2565 or ask me if you need any part
this is what I have as my code
@Composable
fun UpdatePasswordScreen(
viewModel: UpdatePasswordViewModel = hiltViewModel(),
navigateBack: () -> Unit
) {
val uiState by viewModel.updatePasswordUiState.collectAsStateWithLifecycle()
UpdatePasswordScreen(
uiState = uiState,
navigateBack = navigateBack
)
}
@Composable
fun UpdatePasswordScreen(
uiState: RegistrationUiState,
navigateBack: () -> Unit
) {
val context = LocalContext.current
val snackbarHostState = remember { SnackbarHostState() }
Scaffold(snackbarHost = {
SnackbarHost(hostState = snackbarHostState)
}, topBar = {
MifosTopBar(
title = { Text(text = stringResource(id = R.string.change_password)) },
navigateBack = navigateBack
)
}) {
Box(
modifier = Modifier.padding(it)
) {
UpdatePasswordContent()
when (uiState) {
is RegistrationUiState.Loading -> {
MifosProgressIndicator(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background.copy(0.8f))
)
}
is RegistrationUiState.Error -> {
LaunchedEffect(snackbarHostState) {
snackbarHostState.showSnackbar(
context.getString(R.string.could_not_update_password_error),
context.getString(R.string.dialog_action_ok),
duration = SnackbarDuration.Short
)
}
}
is RegistrationUiState.Initial -> Unit
is RegistrationUiState.Success -> {
LaunchedEffect(snackbarHostState) {
snackbarHostState.showSnackbar(
context.getString(R.string.password_changed_successfully),
context.getString(R.string.dialog_action_ok),
duration = SnackbarDuration.Short
)
}
navigateBack.invoke()
}
}
}
}
}
here UpdatePasswordContent()
constains screen content. Let me please know if you need anything else