Posts

Showing posts from June, 2019

Forms in Flutter (Validator and UI)

How to create a form Widget with validators in 3 simple steps I. C8 Global key in a Stateful Widget II. Add Validator to TextFormField Widget III. With Form Key, see Current State and Invoke the validate method Step I: C8 Global key in a Stateful Widget class MyCustomFormState extends State<MyCustomForm> {   final _formKey = GlobalKey<FormState>();   @override   Widget build(BuildContext context) {     return Form(       key: _formKey,       child: HomePage());}} Step II: Add Validator to TextFormField Widget TextFormField(   validator: (form_value) {     if (form_value.isEmpty) {       return 'Please enter some text'}     return null; },); Step III: With Form Key, see Current State and Invoke the validate method RaisedButton(   onPressed: () {     if (_formKey.currentState.validate()) {       Scaffold...