flutter-building-forms
Builds Flutter forms with validation and user input handling. Use when creating login screens, data entry forms, or any multi-field user input.
- License 许可
- MIT
- 最近更新
- 2026-06-13
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- flutter-building-forms
- description
- Builds Flutter forms with validation and user input handling. Use when creating login screens, data entry forms, or any multi-field user input.
03 SKILL.md 正文
Building Validated Forms
Contents
Form Architecture
Implement forms using a Form widget to group and validate multiple input fields together.
- Use a StatefulWidget: Always host your
Forminside aStatefulWidget. - Persist the GlobalKey: Instantiate a
GlobalKey<FormState>exactly once as a final variable within theStateclass. Do not generate a newGlobalKeyinside thebuildmethod. - Bind the Key: Pass the
GlobalKey<FormState>to thekeyproperty of theFormwidget. - Alternative Access: Use
Form.of(context)to access theFormStatefrom a descendant widget.
Field Validation
Use TextFormField for Material Design text inputs with built-in validation.
- Implement the Validator: Provide a
validator()callback to eachTextFormField. - Return Error Messages: If invalid, return a
Stringwith the error message. - Return Null for Success: If valid, return
null.
Workflow: Implementing a Validated Form
- [ ] Create a
StatefulWidgetand itsStateclass. - [ ] Instantiate
final _formKey = GlobalKey<FormState>();in theStateclass. - [ ] Return a
Formwidget inbuildand assignkey: _formKey. - [ ] Add
TextFormFieldwidgets as descendants of theForm. - [ ] Write a
validatorfunction for each field (returnStringon error,nullon success). - [ ] Add a submit button.
- [ ] Validate in
onPressedusing_formKey.currentState!.validate().
Validation Decision Logic
- Call
_formKey.currentState!.validate(). - If
true: Proceed with submission (save data, API call) and show success (SnackBar). - If
false: Error messages display automatically. User adjusts input and resubmits.
Examples
Complete Validated Form
class UserRegistrationForm extends StatefulWidget {
const UserRegistrationForm({super.key});
@override
State<UserRegistrationForm> createState() => _UserRegistrationFormState();
}
class _UserRegistrationFormState extends State<UserRegistrationForm> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextFormField(
decoration: const InputDecoration(
labelText: 'Username',
hintText: 'Enter your username',
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter a username';
}
if (value.length < 4) {
return 'Username must be at least 4 characters';
}
return null;
},
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Processing Data')),
);
}
},
child: const Text('Submit'),
),
],
),
);
}
}
04 同仓库更多 Skills
hello-checker
Use this skill when asked to "verify", "check", or "validate" a file's existence and content. It provides a reliable workflow for confirming files meet their spec.
ask-skill
暂无简介
html-review-artifact
Framework-wide guidance for crafting polished human-review artifacts as markdown or HTML
converge-planning
Design a Converge playbook end-to-end. Use when the user says "plan a project", "design a playbook", "decompose into tasks", "scaffold a Converge workflow", "onboard to Converge", or asks how to write TASK.md / playbook.yml. Two entry points: plan a new playbook or update an existing one. Hand off to `/converge-control` after producing the playbook structure.
converge-control
Operate a Converge playbook end-to-end — start runs, monitor progress, narrow failures with `--select`, inspect runtime state, validate definitions, surgically reset subtrees, and stop stuck or orphaned runs. Use this skill whenever the user says "run my playbook", "execute this", "monitor the run", "converge failed", "the run is stuck", "retry failures", "babysit this playbook", "what's the status?", "show me the gantt", or asks how to use `converge run` / `--select` / `inspect` / `doctor` / `clean` / `stop`. Also use it for `HTTP 401` / `Invalid API key` failures on the first task — those are environment-not-playbook problems — and for any post-run cleanup work. Hand off to `converge-planning` if the user wants to design or restructure the playbook itself.
repair-taskts
Fix task.ts definition issues — Seed syntax, missing .build(), empty checks, import errors, TypeScript errors