చాలా అనువర్తనాలకు ఫారమ్లు (లాగిన్, సైన్అప్, డేటా ఎంట్రీ) ఉందని, ఇవి యూజర్ ఇన్పుట్ హ్యాండ్లింగ్ మరియు వాలిడేషన్ అవసరం. Flutter Form, TextFormField, validators, మరియు controllers ప్రদానం చేస్తుంది ఫారమ్లను నిర్మించడానికి మరియు వాలిడేట్ చేయడానికి — ఇది ఏ యూజర్ ఇన్పుట్ కలిగిన అనువర్తనానికైనా అవసరం.
Form మరియు TextFormField
final _formKey = GlobalKey<FormState>(); // a key to access the form's state
Form(
key: _formKey,
child: Column(children: [
TextFormField(
decoration: InputDecoration(labelText: 'Email'),
validator: (value) { // VALIDATION logic
if (value == null || value.isEmpty) return 'Email required';
if (!value.contains('@')) return 'Invalid email';
return null; // null = valid
},
),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) { // run all validators
// all fields valid → submit
}
},
child: Text('Submit'),
),
]),
)
