For Forms, Validation & Focus, define the source of truth, validation, focus, controller disposal, and minimal rebuild boundary. Keep ephemeral state local and place shared app state in a testable controller or model.
Build a Complete Mental Model
For Forms, Validation & Focus, define the source of truth, validation, focus, controller disposal, and minimal rebuild boundary. Keep ephemeral state local and place shared app state in a testable controller or model.
Apply It in Production Flutter
Run and test an original Forms, Validation & Focus example with small and large screens, text scaling, empty/loading/error states, rapid interaction, navigation restoration, and disposal cases. Use flutter analyze, widget tests, and profile mode where relevant.
After This Lesson
final formKey = GlobalKey<FormState>();
Form(
key: formKey,
child: Column(children: [
TextFormField(
decoration: const InputDecoration(labelText: 'Email'),
validator: (value) => (value?.contains('@') ?? false) ? null : 'Enter a valid email',
),
FilledButton(
onPressed: () => formKey.currentState!.validate(),
child: const Text('Submit'),
),
]),
)Invalid input shows an inline validation messageTry It Yourself
Run and test an original Forms, Validation & Focus example with small and large screens, text scaling, empty/loading/error states, rapid interaction, navigation restoration, and disposal cases. Use flutter analyze, widget tests, and profile mode where relevant.
Lifecycle and Performance Warning
Assuming one screen's sample output proves every rebuild, overflow, accessibility, async, and lifecycle path.
Flutter documentation — Flutter