ရိုးရိုးလေး ရှင်းပြမယ်
Handling Gestures ကို ရိုးရိုးလေးနားလည်မယ်
Button မဟုတ်တဲ့ Container, Image, Card, Icon စတဲ့ widget တွေကို user interaction ရချင်ရင် GestureDetector နဲ့ wrap လုပ်နိုင်ပါတယ်။ ဥပမာ product card ကို tap လိုက်ရင် detail page သို့သွားတာ၊ image ကို double tap လုပ်ရင် favorite ဖြစ်တာတွေမှာအသုံးများပါတယ်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
GestureDetector ကို child မရှိဘဲထားရင် tap လုပ်စရာ area မရှိပါ။ Child widget ကိုသေချာထည့်ပါ။
ဖြစ်လေ့ရှိတဲ့အမှား
Screen တစ်မျိုးတွင် sample output မှန်ရုံဖြင့် rebuild, overflow, accessibility, async နဲ့ lifecycle paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Handling Gestures မှာ 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
Handling Gestures ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
GestureDetector(
onTap: () {
print('Card tapped');
},
onLongPress: () {
print('Card long pressed');
},
child: Container(
width: 180,
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(14),
),
child: const Center(
child: Text('Tap this card'),
),
),
)Handling Gestures မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Input + state
GestureDetector(Button မဟုတ်တဲ့ Container, Image, Card, Icon စတဲ့ widget တွေကို user interaction ရချင်ရင် GestureDetector နဲ့ wrap လုပ်နိုင်ပါတယ်။ ဥပမာ product card ကို tap လိုက်ရင် detail page သို့သွားတာ၊ image ကို double tap လုပ်ရင် favorite ဖြစ်တာတွေမှာအသုံးများပါတယ်။
- Widget build + layout
padding: const EdgeInsets.all(18),Handling Gestures မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
- Rendered Flutter UI
)Handling Gestures 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
Handling Gestures ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
Failure
GestureDetector ကို child မရှိဘဲထားရင် tap လုပ်စရာ area မရှိပါ။ Child widget ကိုသေချာထည့်ပါ။
Button မဟုတ်တဲ့ Container, Image, Card, Icon စတဲ့ widget တွေကို user interaction ရချင်ရင် GestureDetector နဲ့ wrap လုပ်နိုင်ပါတယ်။ ဥပမာ product card ကို tap လိုက်ရင် detail page သို့သွားတာ၊ image ကို double tap လုပ်ရင် favorite ဖြစ်တာတွေမှာအသုံးများပါတယ်။
GestureDetector(
onTap: () {
print('Card tapped');
},
onLongPress: () {
print('Card long pressed');
},
child: Container(
width: 180,
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(14),
),
child: const Center(
child: Text('Tap this card'),
),
),
)အစိမ်းရောင် card ပေါ်လာပြီး tap သို့မဟုတ် long press လုပ်တဲ့အခါ console မှာ message ပေါ်ပါမယ်။နောက်တစ်ဆင့်
User ကစာရိုက်ထည့်နိုင်တဲ့ TextField နဲ့ form input ကိုဆက်သင်ပါ။
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Handling Gestures 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
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Handling Gestures 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 ကိုခန့်မှန်းပါ
GestureDetector(
onTap: () {
print('Card tapped');
},
onLongPress: () {
print('Card long pressed');
},
child: Container(
width: 180,
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(14),
),
child: const Center(
child: Text('Tap this card'),
),
),
)ရလဒ်: Handling Gestures ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Handling Gestures 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
- Handling Gestures မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
- GestureDetector ကို child မရှိဘဲထားရင် tap လုပ်စရာ area မရှိပါ။ Child widget ကိုသေချာထည့်ပါ။
- Handling Gestures 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