Globales Ranking · von 600 Skills
flutter-building-forms AI Agent Skill
Quellcode ansehen: flutter/skills
SafeInstallation
npx skills add flutter/skills --skill flutter-building-forms 6.3K
Installationen
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; doing so is resource-expensive and destroys the form's state on every rebuild. - Bind the Key: Pass the
GlobalKey<FormState>to thekeyproperty of theFormwidget. This uniquely identifies the form and provides access to theFormStatefor validation and submission. - Alternative Access: If dealing with highly complex widget trees where passing the key is impractical, use
Form.of(context)to access theFormStatefrom a descendant widget.
Field Validation
Use TextFormField to render Material Design text inputs with built-in validation support. TextFormField is a convenience widget that automatically wraps a standard TextField inside a FormField.
- Implement the Validator: Provide a
validator()callback function to eachTextFormField. - Return Error Messages: If the user's input is invalid, return a
Stringcontaining the specific error message. TheFormwill automatically rebuild to display this text below the field. - Return Null for Success: If the input passes validation, you must return
null.
Workflow: Implementing a Validated Form
Follow this sequential workflow to implement and validate a form. Copy the checklist to track your progress.
Task Progress:
-
- Create a
StatefulWidgetand its correspondingStateclass.
- Create a
-
- Instantiate
final _formKey = GlobalKey<FormState>();in theStateclass.
- Instantiate
-
- Return a
Formwidget in thebuildmethod and assignkey: _formKey.
- Return a
-
- Add
TextFormFieldwidgets as descendants of theForm.
- Add
-
- Write a
validatorfunction for eachTextFormField(returnStringon error,nullon success).
- Write a
-
- Add a submit button (e.g.,
ElevatedButton).
- Add a submit button (e.g.,
-
- Implement the validation check in the button's
onPressedcallback using_formKey.currentState!.validate().
- Implement the validation check in the button's
Validation Decision Logic
When the user triggers the submit action, execute the following conditional logic:
- Call
_formKey.currentState!.validate(). - If
true(Valid): All validators returnednull. Proceed with form submission (e.g., save data, make API call) and display a success indicator (e.g., aSnackBar). - If
false(Invalid): One or more validators returned an error string. TheFormStateautomatically rebuilds the UI to display the error messages. - Feedback Loop: Run validator -> review errors -> fix. The user must adjust their input and resubmit until
validate()returnstrue.
Examples
Complete Validated Form Implementation
Use the following pattern to implement a robust, validated form.
import 'package:flutter/material.dart';
class UserRegistrationForm extends StatefulWidget {
const UserRegistrationForm({super.key});
@override
State<UserRegistrationForm> createState() => _UserRegistrationFormState();
}
class _UserRegistrationFormState extends State<UserRegistrationForm> {
// 1. Persist the GlobalKey in the State class
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
// 2. Bind the key to the Form
return Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 3. Add TextFormFields with validators
TextFormField(
decoration: const InputDecoration(
labelText: 'Username',
hintText: 'Enter your username',
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter a username'; // Error state
}
if (value.length < 4) {
return 'Username must be at least 4 characters'; // Error state
}
return null; // Valid state
},
),
const SizedBox(height: 16),
// 4. Add the submit button
ElevatedButton(
onPressed: () {
// 5. Trigger validation logic
if (_formKey.currentState!.validate()) {
// Form is valid: Process data
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Processing Data')),
);
} else {
// Form is invalid: Errors are automatically displayed
debugPrint('Form validation failed.');
}
},
child: const Text('Submit'),
),
],
),
);
}
}Installationen
Sicherheitsprüfung
Quellcode ansehen
flutter/skills
Mehr aus dieser Quelle
Power your AI Agents with
the best open-source models.
Drop-in OpenAI-compatible API. No data leaves Europe.
Explore Inference APIGLM
GLM 5
$1.00 / $3.20
per M tokens
Kimi
Kimi K2.5
$0.60 / $2.80
per M tokens
MiniMax
MiniMax M2.5
$0.30 / $1.20
per M tokens
Qwen
Qwen3.5 122B
$0.40 / $3.00
per M tokens
So verwenden Sie diesen Skill
Install flutter-building-forms by running npx skills add flutter/skills --skill flutter-building-forms in your project directory. Führen Sie den obigen Installationsbefehl in Ihrem Projektverzeichnis aus. Die Skill-Datei wird von GitHub heruntergeladen und in Ihrem Projekt platziert.
Keine Konfiguration erforderlich. Ihr KI-Agent (Claude Code, Cursor, Windsurf usw.) erkennt installierte Skills automatisch und nutzt sie als Kontext bei der Code-Generierung.
Der Skill verbessert das Verständnis Ihres Agenten für flutter-building-forms, und hilft ihm, etablierte Muster zu befolgen, häufige Fehler zu vermeiden und produktionsreifen Code zu erzeugen.
Was Sie erhalten
Skills sind Klartext-Anweisungsdateien — kein ausführbarer Code. Sie kodieren Expertenwissen über Frameworks, Sprachen oder Tools, das Ihr KI-Agent liest, um seine Ausgabe zu verbessern. Das bedeutet null Laufzeit-Overhead, keine Abhängigkeitskonflikte und volle Transparenz: Sie können jede Anweisung vor der Installation lesen und prüfen.
Kompatibilität
Dieser Skill funktioniert mit jedem KI-Coding-Agenten, der das skills.sh-Format unterstützt, einschließlich Claude Code (Anthropic), Cursor, Windsurf, Cline, Aider und anderen Tools, die projektbezogene Kontextdateien lesen. Skills sind auf Transportebene framework-agnostisch — der Inhalt bestimmt, für welche Sprache oder welches Framework er gilt.
Chat with 100+ AI Models in one App.
Use Claude, ChatGPT, Gemini alongside with EU-Hosted Models like Deepseek, GLM-5, Kimi K2.5 and many more.