ရိုးရိုးလေး ရှင်းပြမယ်
Input & Forms (TextField) ကို ရိုးရိုးလေးနားလည်မယ်
TextField က user ဆီက text input ရယူဖို့သုံးပါတယ်။ Login form, search box, contact form, comment box စတဲ့နေရာတိုင်းမှာအသုံးဝင်ပါတယ်။ TextEditingController ကိုသုံးရင် input ထဲကစာကိုဖတ်နိုင်ပြီး dispose() ထဲမှာ controller ကိုရှင်းပေးတာက memory leak မဖြစ်အောင် ကောင်းတဲ့အလေ့အကျင့်ပါ။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
TextEditingController ကိုဖန်တီးပြီး dispose မလုပ်တာက project ကြီးလာရင် memory ပြဿနာဖြစ်နိုင်ပါတယ်။
ဖြစ်လေ့ရှိတဲ့အမှား
Screen တစ်မျိုးတွင် sample output မှန်ရုံဖြင့် rebuild, overflow, accessibility, async နဲ့ lifecycle paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Input & Forms (TextField) မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
- Input + state
- Widget build + layout
- Rendered Flutter UI
Input & Forms (TextField) ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
class NameForm extends StatefulWidget {
const NameForm({super.key});
@override
State<NameForm> createState() => _NameFormState();
}
class _NameFormState extends State<NameForm> {
final nameController = TextEditingController();
String greeting = '';
@override
void dispose() {
nameController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
TextField(
controller: nameController,
decoration: const InputDecoration(
labelText: 'Enter your name',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 12),
ElevatedButton(
onPressed: () {
setState(() {
greeting = 'Hello, ${nameController.text}';
});
},
child: const Text('Submit'),
),
Text(greeting),
],
);
}
}Input & Forms (TextField) မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Input + state
class NameForm extends StatefulWidget {TextField က user ဆီက text input ရယူဖို့သုံးပါတယ်။ Login form, search box, contact form, comment box စတဲ့နေရာတိုင်းမှာအသုံးဝင်ပါတယ်။ TextEditingController ကိုသုံးရင် input ထဲကစာကိုဖတ်နိုင်ပြီး dispose() ထဲမှာ controller ကိုရှင်းပေးတာက memory leak မဖြစ်အောင် ကောင်းတဲ့အလေ့အကျင့်ပါ။
- Widget build + layout
decoration: const InputDecoration(Input & Forms (TextField) မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
- Rendered Flutter UI
}Input & Forms (TextField) example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။
- Input + state
- Widget build + layout
- Rendered Flutter UI
Success
Input & Forms (TextField) ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
Failure
TextEditingController ကိုဖန်တီးပြီး dispose မလုပ်တာက project ကြီးလာရင် memory ပြဿနာဖြစ်နိုင်ပါတယ်။
TextField က user ဆီက text input ရယူဖို့သုံးပါတယ်။ Login form, search box, contact form, comment box စတဲ့နေရာတိုင်းမှာအသုံးဝင်ပါတယ်။ TextEditingController ကိုသုံးရင် input ထဲကစာကိုဖတ်နိုင်ပြီး dispose() ထဲမှာ controller ကိုရှင်းပေးတာက memory leak မဖြစ်အောင် ကောင်းတဲ့အလေ့အကျင့်ပါ။
class NameForm extends StatefulWidget {
const NameForm({super.key});
@override
State<NameForm> createState() => _NameFormState();
}
class _NameFormState extends State<NameForm> {
final nameController = TextEditingController();
String greeting = '';
@override
void dispose() {
nameController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
TextField(
controller: nameController,
decoration: const InputDecoration(
labelText: 'Enter your name',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 12),
ElevatedButton(
onPressed: () {
setState(() {
greeting = 'Hello, ${nameController.text}';
});
},
child: const Text('Submit'),
),
Text(greeting),
],
);
}
}Name ထည့်ပြီး Submit နှိပ်လိုက်ရင် အောက်မှာ Hello, name ဆိုပြီး greeting ပေါ်လာပါမယ်။နောက်တစ်ဆင့်
Input ကနေ state ပြောင်းလာပြီဆိုရင် State Management concept ကိုဆက်ဖတ်ပါ။
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Input & Forms (TextField) example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Input & Forms (TextField) example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
class NameForm extends StatefulWidget {
const NameForm({super.key});
@override
State<NameForm> createState() => _NameFormState();
}
class _NameFormState extends State<NameForm> {
final nameController = TextEditingController();
String greeting = '';
@override
void dispose() {
nameController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
TextField(
controller: nameController,
decoration: const InputDecoration(
labelText: 'Enter your name',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 12),
ElevatedButton(
onPressed: () {
setState(() {
greeting = 'Hello, ${nameController.text}';
});
},
child: const Text('Submit'),
),
Text(greeting),
],
);
}
}ရလဒ်: Input & Forms (TextField) ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Input & Forms (TextField) example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Input + state → Widget build + layout → Rendered Flutter UI
- Input & Forms (TextField) မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
- TextEditingController ကိုဖန်တီးပြီး dispose မလုပ်တာက project ကြီးလာရင် memory ပြဿနာဖြစ်နိုင်ပါတယ်။
- Input & Forms (TextField) example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။
Flutter documentation — Flutter