Thuta Learning
Flutter
IntermediateMobile Developmentအခြေခံ

Input & Forms (TextField)

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

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

  • Input & Forms (TextField) ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
  • Responsive, failure နဲ့ interaction cases စမ်းနိုင်ရန်
  • Accessible, testable, performant Flutter code ရေးနိုင်ရန်

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

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

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

Input & Forms (TextField) ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်

အဓိက Syntax / Pattern

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

  1. Input + stateclass NameForm extends StatefulWidget {

    TextField က user ဆီက text input ရယူဖို့သုံးပါတယ်။ Login form, search box, contact form, comment box စတဲ့နေရာတိုင်းမှာအသုံးဝင်ပါတယ်။ TextEditingController ကိုသုံးရင် input ထဲကစာကိုဖတ်နိုင်ပြီး dispose() ထဲမှာ controller ကိုရှင်းပေးတာက memory leak မဖြစ်အောင် ကောင်းတဲ့အလေ့အကျင့်ပါ။

  2. Widget build + layoutdecoration: const InputDecoration(

    Input & Forms (TextField) မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။

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

Execution Flow
  1. Input + state
  2. Widget build + layout
  3. 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 မဖြစ်အောင် ကောင်းတဲ့အလေ့အကျင့်ပါ။

dart
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),
      ],
    );
  }
}
You should see
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 ကိုခန့်မှန်းပါ
dart
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

Input & Forms (TextField) ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

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

Quick Quiz 3 / 3

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

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

  • 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

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

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

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

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

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: Name ထည့်ပြီး Submit နှိပ်လိုက်ရင် အောက်မှာ Hello, name ဆိုပြီး greeting ပေါ်လာပါမယ်။

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

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

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

Input & Forms (TextField) | Thuta Learning