In this demo, we will show a snack bar if we log in when having a valid email and password. So, we need an obscurePassword boolean field which will be true by default.Īfter tapping on login, we will either succeed or fail. We also have a show/hide password option and the password will remain hidden (obscured) by default. So, we also need a showErrorMessage boolean field that will be false by default. Only once the login button is pressed, and if the email and password combination is invalid then we want the warnings to begin getting displayed. We don’t want the validation logic to kick in as soon as our app starts. So, we will need a isSubmitting boolean field that will be false by default. What field should be present in the state class? We need to pass back the validated email and password to our UI.Īlso, on pressing the login button, a loading indicator appears until a response is received from the backend. Let’s have a look at what we often see in simple projects where a login() method is implemented. Also, build_runner and freezed as your dev-dependencies. You will be needing dartz, equatable, flutter_bloc, and freezed_annotation as your dependencies. Now let’s take a look at how to perform form validation - the right way.īefore anything, let’s add some dependencies and dev-dependencies that we will require for this project. Now, if you are further reading this article, I assume you agree with me. There should never be room for a simple workaround. Many might argue that for something as simple as this is, it is not necessary to be concerned about architecture and do it as shown above but as developers, we should have developer ethics and we should do things in the right way. It definitely works as intended but it is bad from an architectural point of view. Enter fullscreen mode Exit fullscreen modeĪs you can see, this is how someone would perform form validation with all validation logic right in the UI.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |