ရိုးရိုးလေး ရှင်းပြမယ်
Buttons ကို ရိုးရိုးလေးနားလည်မယ်
Button က user action ကို app ထဲသို့ဝင်လာစေတဲ့တံခါးပါ။ Flutter မှာ ElevatedButton, TextButton, OutlinedButton, IconButton စတဲ့ button အမျိုးအစားတွေရှိပါတယ်။ Button တစ်ခုအလုပ်လုပ်ဖို့ အရေးကြီးဆုံးက onPressed callback ပါ။ onPressed မရှိရင် button က disabled ဖြစ်သွားပါတယ်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
onPressed: null လို့ထားရင် button disabled ဖြစ်ပါတယ်။ Function ချိတ်ချင်ရင် onPressed: () { ... } ပုံစံသုံးပါ။
ဖြစ်လေ့ရှိတဲ့အမှား
Screen တစ်မျိုးတွင် sample output မှန်ရုံဖြင့် rebuild, overflow, accessibility, async နဲ့ lifecycle paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Buttons မှာ 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
Buttons ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
print('Primary action clicked');
},
child: const Text('Save'),
),
TextButton(
onPressed: () {
print('Secondary action clicked');
},
child: const Text('Cancel'),
),
],
)Buttons မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Input + state
Column(Button က user action ကို app ထဲသို့ဝင်လာစေတဲ့တံခါးပါ။ Flutter မှာ ElevatedButton, TextButton, OutlinedButton, IconButton စတဲ့ button အမျိုးအစားတွေရှိပါတယ်။ Button တစ်ခုအလုပ်လုပ်ဖို့ အရေးကြီးဆုံးက onPressed callback ပါ။ onPressed မရှိရင် button က disabled ဖြစ်သွားပါတယ်။
- Widget build + layout
),Buttons မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
- Rendered Flutter UI
)Buttons 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
Buttons ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
Failure
onPressed: null လို့ထားရင် button disabled ဖြစ်ပါတယ်။ Function ချိတ်ချင်ရင် onPressed: () { ... } ပုံစံသုံးပါ။
Button က user action ကို app ထဲသို့ဝင်လာစေတဲ့တံခါးပါ။ Flutter မှာ ElevatedButton, TextButton, OutlinedButton, IconButton စတဲ့ button အမျိုးအစားတွေရှိပါတယ်။ Button တစ်ခုအလုပ်လုပ်ဖို့ အရေးကြီးဆုံးက onPressed callback ပါ။ onPressed မရှိရင် button က disabled ဖြစ်သွားပါတယ်။
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
print('Primary action clicked');
},
child: const Text('Save'),
),
TextButton(
onPressed: () {
print('Secondary action clicked');
},
child: const Text('Cancel'),
),
],
)Save နှင့် Cancel button နှစ်ခု ပေါ်လာပြီး နှိပ်တဲ့အခါ debug console မှာ သက်ဆိုင်ရာ message ပေါ်ပါမယ်။နောက်တစ်ဆင့်
Button မဟုတ်တဲ့ widget တွေကိုပါ tap လုပ်နိုင်အောင် GestureDetector ကိုဆက်လေ့လာပါ။
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Buttons 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
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Buttons 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 ကိုခန့်မှန်းပါ
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
print('Primary action clicked');
},
child: const Text('Save'),
),
TextButton(
onPressed: () {
print('Secondary action clicked');
},
child: const Text('Cancel'),
),
],
)ရလဒ်: Buttons ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Buttons 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
- Buttons မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
- onPressed: null လို့ထားရင် button disabled ဖြစ်ပါတယ်။ Function ချိတ်ချင်ရင် onPressed: () { ... } ပုံစံသုံးပါ။
- Buttons 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