TextField
TextField(
decoration: InputDecoration(
labelText: "الاسم",
border: OutlineInputBorder(),
),
onChanged: (value) => print(value),
)
TextEditingController
لقراءة/التحكّم بقيمة الحقل:
final controller = TextEditingController();
TextField(controller: controller);
ElevatedButton(
onPressed: () => print(controller.text),
child: Text("إرسال"),
);
⚠️ نظّف المتحكّم في
dispose()لتفادي تسرّب الذاكرة.
Form مع التحقّق
final _formKey = GlobalKey<FormState>();
Form(
key: _formKey,
child: Column(children: [
TextFormField(
validator: (value) =>
(value == null || value.isEmpty) ? "الحقل مطلوب" : null,
),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
// البيانات صالحة
}
},
child: Text("تأكيد"),
),
]),
)
🎯 التالي: التنسيق والثيمات.