Thuta Learning
Flutter
IntermediateMobile Developmentအခြေခံ

Handling Gestures

Flutterသင်ခန်းစာ 1320 မိနစ်

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Handling Gestures ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
  • Responsive, failure နဲ့ interaction cases စမ်းနိုင်ရန်
  • Accessible, testable, performant Flutter code ရေးနိုင်ရန်

ရိုးရိုးလေး ရှင်းပြမယ်

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 တစ်ခုကပိုင်ဆိုင်စေပါ။

Mental Model
  1. Input + state
  2. Widget build + layout
  3. Rendered Flutter UI

Handling Gestures ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်

အဓိက Syntax / Pattern

dart
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 ကို အဆင့်လိုက်ဖတ်မယ်

  1. Input + stateGestureDetector(

    Button မဟုတ်တဲ့ Container, Image, Card, Icon စတဲ့ widget တွေကို user interaction ရချင်ရင် GestureDetector နဲ့ wrap လုပ်နိုင်ပါတယ်။ ဥပမာ product card ကို tap လိုက်ရင် detail page သို့သွားတာ၊ image ကို double tap လုပ်ရင် favorite ဖြစ်တာတွေမှာအသုံးများပါတယ်။

  2. Widget build + layoutpadding: 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 တစ်ခုကပိုင်ဆိုင်စေပါ။

  3. 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 ကိုလိုအပ်သလိုသုံးပါ။

Execution Flow
  1. Input + state
  2. Widget build + layout
  3. 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 ဖြစ်တာတွေမှာအသုံးများပါတယ်။

dart
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'),
    ),
  ),
)
You should see
အစိမ်းရောင် 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 ကိုခန့်မှန်းပါ
dart
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

Handling Gestures ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

ဘယ်အမှားကို အရင်ဆုံးရှောင်သင့်လဲ။

Quick Quiz 3 / 3

Real project မှာ ဘယ်လိုအသုံးချသင့်လဲ။

ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ

  • 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

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • GestureDetector ကို child မရှိဘဲထားရင် tap လုပ်စရာ area မရှိပါ။ Child widget ကိုသေချာထည့်ပါ။
  • Screen တစ်မျိုးတွင် sample output မှန်ရုံဖြင့် rebuild, overflow, accessibility, async နဲ့ lifecycle paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
  • build() ထဲ expensive work လုပ်ခြင်း၊ controller/subscription မပိတ်ခြင်း သို့ setState ကိုကျယ်သော subtree ပေါ်ခေါ်ခြင်း။

လက်တွေ့လေ့ကျင့်ခန်း

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 ကိုလိုအပ်သလိုသုံးပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: အစိမ်းရောင် card ပေါ်လာပြီး tap သို့မဟုတ် long press လုပ်တဲ့အခါ console မှာ message ပေါ်ပါမယ်။

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Handling Gestures | Thuta Learning