Thuta Learning
ရှာဖွေရန်
IntermediateMobile Developmentbeginner

Buttons

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Button က user action ကို app ထဲသို့ဝင်လာစေတဲ့တံခါးပါ။ Flutter မှာ ElevatedButton, TextButton, OutlinedButton, IconButton စတဲ့ button အမျိုးအစားတွေရှိပါတယ်။ Button တစ်ခုအလုပ်လုပ်ဖို့ အရေးကြီးဆုံးက onPressed callback ပါ။ onPressed မရှိရင် button က disabled ဖြစ်သွားပါတယ်။

dart
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'),
    ),
  ],
)
You should see
Save နှင့် Cancel button နှစ်ခု ပေါ်လာပြီး နှိပ်တဲ့အခါ debug console မှာ သက်ဆိုင်ရာ message ပေါ်ပါမယ်။

နောက်တစ်ဆင့်

Button မဟုတ်တဲ့ widget တွေကိုပါ tap လုပ်နိုင်အောင် GestureDetector ကိုဆက်လေ့လာပါ။

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

  • onPressed: null လို့ထားရင် button disabled ဖြစ်ပါတယ်။ Function ချိတ်ချင်ရင် onPressed: () { ... } ပုံစံသုံးပါ။
Buttons | Thuta Learning