In this video we'll explore a pattern for validating data in Flutter using just the Provider package with no streams or BLoCs. Article: julow.com/article/1 Github: github.com/nhandrew/validatio... Social Media: / andyjulow
I have been following all your tutorials on flutter. Thanks to you I understand flutter now and i am enjoying it. Your methods of teaching is very simple, clear and comprehensive. I had to abandon the Udemy courses i am taking on flutter. I am still getting a hang of it, but with you holding my hand, I should be able to stand in a short time. Thank you very much and God bless you. Emmanuel Lagos, Nigeria
Thanks for your tutorial. Your explonation was very helpfull for me. I see that because you have one provider for all fields on screen, when value changed in one field, other fields also rebuilds, isn't it better to have separate provider each field? What if for example create parent class with ChangeNotifier (for example StandartTextFieldValidation with ChangeNotifier) write there common logic and create children classes for each provider for each field in form?
Yes, whenever you trigger the notifyListeners() method, the whole UI rebuilds. To avoid a larger UI rebuild, you could use a consumer or selector widget which enables you to change a small part of the UI.
thank you Andy, after submitting the form i want add a navigate to a new screen how to do that? onPressed: (!validationService.isValid) ? null : validationService.submitData //here i want the navigation
Hi Mohamed, one approach would be to declare a stream in signup_validation.dart that you pass a value to in the submitdata function to indicate the record save is complete. You can then convert the signup page to a stateful widget and setup a listener to listen for changes and Navigate to the desired page.
You could also do something like this bool isValid() { if (_email.value != null && _password.value != null) { print('${_email.value} + $_password'); return true; } else { return false; } notifyListeners(); } and then in your sign in page onPressed: validationService.isValid() ? () { validationService.submitData(context); } : null, then your submit can be like this for example void submitData(BuildContext context) { Navigator.pushNamed(context, NavigationDrawer.id); }