ရိုးရိုးလေး ရှင်းပြမယ်
State Management Intro ကို ရိုးရိုးလေးနားလည်မယ်
State ဆိုတာ app ရဲ့ လက်ရှိအခြေအနေပါ။ ဥပမာ counter number, login user, selected tab, cart item count, API result, loading/error status — အားလုံး state ဖြစ်နိုင်ပါတယ်။ State Management ဆိုတာ ဒီအခြေအနေတွေကို ဘယ်နေရာမှာသိမ်းမလဲ၊ ဘယ်လိုပြောင်းမလဲ၊ UI ကိုဘယ်လို update လုပ်မလဲဆိုတာ စီမံခြင်းပါ။ အစပိုင်းမှာ setState() နဲ့စတာအကောင်းဆုံးပါ။ Project ကြီးလာရင် Provider, Riverpod, BLoC, GetX စတာတွေကိုရွေးချယ်နိုင်ပါတယ်။ သို့သော် အခြေခံကိုမသိဘဲ advanced package တက်သွားရင် မုန့်ဟင်းခါးမသိဘဲ molecular gastronomy ချက်သလိုဖြစ်တတ်ပါတယ်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
State ကိုနေရာတိုင်းမှာကော်ပီကူးသိမ်းထားရင် data မတူတော့တဲ့ bug တွေဖြစ်တတ်ပါတယ်။ Single source of truth ကိုစဉ်းစားပါ။
ဖြစ်လေ့ရှိတဲ့အမှား
Screen တစ်မျိုးတွင် sample output မှန်ရုံဖြင့် rebuild, overflow, accessibility, async နဲ့ lifecycle paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
State Management Intro မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
- Event
- State owner + notifier
- Rebuilt widgets
State Management Intro ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
// Simple state examples
int counter = 0;
bool isLoading = false;
String selectedCategory = 'All';
List<String> cartItems = [];State Management Intro မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Event
// Simple state examplesState ဆိုတာ app ရဲ့ လက်ရှိအခြေအနေပါ။ ဥပမာ counter number, login user, selected tab, cart item count, API result, loading/error status — အားလုံး state ဖြစ်နိုင်ပါတယ်။ State Management ဆိုတာ ဒီအခြေအနေတွေကို ဘယ်နေရာမှာသိမ်းမလဲ၊ ဘယ်လိုပြောင်းမလဲ၊ UI ကိုဘယ်လို update လုပ်မလဲဆိုတာ စီမံခြင်းပါ။ အစပိုင်းမှာ setState() နဲ့စတာအကောင်းဆုံးပါ။ Project ကြီးလာရင် Provider, Riverpod, BLoC, GetX စတာတွေကိုရွေးချယ်နိုင်ပါတယ်။ သို့သော် အခြေခံကိုမသိဘဲ advanced package တက်သွားရင် မုန့်ဟင်းခါးမသိဘဲ molecular gastronomy ချက်သလိုဖြစ်တတ်ပါတယ်။
- State owner + notifier
bool isLoading = false;State Management Intro မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
- Rebuilt widgets
List<String> cartItems = [];State Management Intro example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။
- Event
- State owner + notifier
- Rebuilt widgets
Success
State Management Intro ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
Failure
State ကိုနေရာတိုင်းမှာကော်ပီကူးသိမ်းထားရင် data မတူတော့တဲ့ bug တွေဖြစ်တတ်ပါတယ်။ Single source of truth ကိုစဉ်းစားပါ။
State ဆိုတာ app ရဲ့ လက်ရှိအခြေအနေပါ။ ဥပမာ counter number, login user, selected tab, cart item count, API result, loading/error status — အားလုံး state ဖြစ်နိုင်ပါတယ်။ State Management ဆိုတာ ဒီအခြေအနေတွေကို ဘယ်နေရာမှာသိမ်းမလဲ၊ ဘယ်လိုပြောင်းမလဲ၊ UI ကိုဘယ်လို update လုပ်မလဲဆိုတာ စီမံခြင်းပါ။ အစပိုင်းမှာ setState() နဲ့စတာအကောင်းဆုံးပါ။ Project ကြီးလာရင် Provider, Riverpod, BLoC, GetX စတာတွေကိုရွေးချယ်နိုင်ပါတယ်။ သို့သော် အခြေခံကိုမသိဘဲ advanced package တက်သွားရင် မုန့်ဟင်းခါးမသိဘဲ molecular gastronomy ချက်သလိုဖြစ်တတ်ပါတယ်။
// Simple state examples
int counter = 0;
bool isLoading = false;
String selectedCategory = 'All';
List<String> cartItems = [];ဒီ code က UI မပြသေးပါ။ State အမျိုးအစားတွေကိုနားလည်စေရန်ပြထားတဲ့ example ဖြစ်ပါတယ်။နောက်တစ်ဆင့်
State ကို UI နဲ့ချိတ်ပြီးပြောင်းဖို့ setState() lesson ကိုဆက်သင်ပါ။
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
State Management Intro 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
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
State Management Intro 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 ကိုခန့်မှန်းပါ
// Simple state examples
int counter = 0;
bool isLoading = false;
String selectedCategory = 'All';
List<String> cartItems = [];ရလဒ်: State Management Intro ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
State Management Intro 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
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Event → State owner + notifier → Rebuilt widgets
- State Management Intro မှာ source of truth, validation, focus, controller disposal နဲ့ minimal rebuild boundary ကိုရှင်းပါ။ Ephemeral state ကို local ထားပြီး shared app state ကို testable controller/model တစ်ခုကပိုင်ဆိုင်စေပါ။
- State ကိုနေရာတိုင်းမှာကော်ပီကူးသိမ်းထားရင် data မတူတော့တဲ့ bug တွေဖြစ်တတ်ပါတယ်။ Single source of truth ကိုစဉ်းစားပါ။
- State Management Intro 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