pref: LaunchedEffect

This commit is contained in:
HuanCheng65 2023-01-06 11:27:17 +08:00
parent 5515e8f457
commit fd8f89153b
No known key found for this signature in database
GPG Key ID: E9031EF91A805148
1 changed files with 13 additions and 9 deletions

View File

@ -184,15 +184,19 @@ fun BlockSettingsPage(
} }
) { paddingValues -> ) { paddingValues ->
val snackbarHostState = LocalSnackbarHostState.current val snackbarHostState = LocalSnackbarHostState.current
coroutineScope.launch { LaunchedEffect(null) {
viewModel.uiEventFlow coroutineScope.launch {
.filterIsInstance<BlockSettingsUiEvent.Success>() viewModel.uiEventFlow
.collect { .filterIsInstance<BlockSettingsUiEvent.Success>()
snackbarHostState.showSnackbar(when (it) { .collect {
is BlockSettingsUiEvent.Success.Add -> context.getString(R.string.toast_add_success) snackbarHostState.showSnackbar(
is BlockSettingsUiEvent.Success.Delete -> context.getString(R.string.toast_delete_success) when (it) {
}) is BlockSettingsUiEvent.Success.Add -> context.getString(R.string.toast_add_success)
} is BlockSettingsUiEvent.Success.Delete -> context.getString(R.string.toast_delete_success)
}
)
}
}
} }
HorizontalPager( HorizontalPager(
count = 2, count = 2,