원클릭으로
flutter-form
Build a form with validation
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Build a form with validation
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
PocketMind 本地无头浏览器爬取架构,适用于小红书/知乎抓取、后台爬虫服务、MethodChannel、Cookie 管理与 MetadataManager 协作场景。
Use when implementing or debugging PocketMind mobile chat flows, including note-scoped sessions, global multi-session switching, sync gating, stream send behavior, and dialog interaction regressions.
PocketMind 后端 notes->resource_records->context_catalog 一致性改造专项 Skill。当用户讨论 resource_records 真相层、context_catalog 索引层、Outbox/Projector、检索 fallback、SessionCommit 长事务、transcript 重复同步或相关回归测试时必须触发。
Use when you need to understand or modify PocketMind note save to resource indexing flow, including outbox, MQ hint/DLQ compensation, projector consumption, and consistency boundaries.
PocketMind 移动端笔记同步架构专项 Skill。当涉及以下问题时必须触发:预览字段(previewTitle等)被同步覆盖、多端一致性与离线冲突问题、同步链路改造(Pull/Push)、UI层违规调用底层Provider、抓取/轮询等写入未进入同步队列、或维护同步守卫测试。
设计、重构和实现 PocketMind 项目中的整体上下文架构(Context Architecture),用于统一规划和落地 resources、user memories、agent memories、tenant skills、session、retrieval、ingestion、storage 与现有 Note/Chat/Asset 的边界。当用户要求为 PocketMind 新增长期记忆、重构 AI 上下文体系、借鉴 OpenViking 的上下文类型/层级/URI/存储/检索/会话思想,或需要分阶段实施 Context Service 时使用。
| name | flutter-form |
| description | Build a form with validation |
| metadata | {"model":"models/gemini-3.1-pro-preview","last_modified":"Wed, 11 Mar 2026 16:47:50 GMT"} |
Implements stateful form validation in Flutter using Form, TextFormField, and GlobalKey<FormState>. Manages validation state efficiently without unnecessary key regeneration and handles user input validation workflows. Assumes a pre-existing Flutter environment with Material Design dependencies available.
When implementing form validation, follow this decision tree to determine the flow of state and UI updates:
_formKey.currentState!.validate().validate() return true?
SnackBar, navigation).FormState automatically rebuilds the TextFormField widgets to display the String error messages returned by their respective validator functions. Halt submission.Initialize the Stateful Form Container
Create a StatefulWidget to hold the form. Instantiate a GlobalKey<FormState> exactly once within the State class to prevent resource-expensive key regeneration during build cycles.
import 'package:flutter/material.dart';
class CustomValidatedForm extends StatefulWidget {
const CustomValidatedForm({super.key});
@override
State<CustomValidatedForm> createState() => _CustomValidatedFormState();
}
class _CustomValidatedFormState extends State<CustomValidatedForm> {
// Instantiate the GlobalKey once in the State object
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// Form fields will be injected here
],
),
);
}
}
Implement TextFormFields with Validation Logic
Inject TextFormField widgets into the Form's widget tree. Provide a validator function for each field.
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your email',
labelText: 'Email',
),
validator: (String? value) {
if (value == null || value.isEmpty) {
return 'Please enter an email address';
}
if (!value.contains('@')) {
return 'Please enter a valid email address';
}
// Return null if the input is valid
return null;
},
onSaved: (String? value) {
// Handle save logic here
},
)
Implement the Submit Action and Validation Trigger
Create a button that accesses the FormState via the GlobalKey to trigger validation.
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
onPressed: () {
// Validate returns true if the form is valid, or false otherwise.
if (_formKey.currentState!.validate()) {
// Save the form fields if necessary
_formKey.currentState!.save();
// Provide success feedback
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Processing Data')),
);
}
},
child: const Text('Submit'),
),
)
STOP AND ASK THE USER: Pause implementation and ask the user for the following context:
Validate-and-Fix Loop After generating the form, verify the following:
_formKey.currentState!.validate() is null-checked properly using the bang operator (!) or safe calls if the key might be detached.validator function explicitly returns null on success. Returning an empty string ("") will trigger an error state with no text.GlobalKey<FormState> inside the build method. It must be a persistent member of the State class.StatelessWidget for the form container unless the GlobalKey is being passed down from a stateful parent.TextField widgets if you require built-in form validation; you must use TextFormField (which wraps TextField in a FormField).null from a validator function when the input is valid.Form widget is a common ancestor to all TextFormField widgets that need to be validated together.