-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor onboarding validation 5103387645092597876 #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,8 +98,9 @@ fun OnboardingScreen( | |
| Button(onClick = { | ||
| if (currentStep == 0) { | ||
| // Save Name | ||
| if (name.isNotEmpty()) { | ||
| viewModel.saveName() | ||
| if (!viewModel.saveName()) { | ||
| Toast.makeText(context, "Name cannot be blank", Toast.LENGTH_SHORT).show() | ||
| return@Button | ||
| } | ||
|
Comment on lines
+101
to
104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This imperative approach to validation has a couple of drawbacks:
A better approach would be to make this UI state-driven. The For example, your ViewModel could manage state like this: // In ViewModel
fun validateAndSaveName() {
if (name.value.isBlank()) {
// Update a UiState object with an error message/ID
} else {
// Clear error and launch save coroutine
}
} |
||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.