ရိုးရိုးလေး ရှင်းပြမယ်
Basic Navigation ကို ရိုးရိုးလေးနားလည်မယ်
Mobile app တစ်ခုမှာ screen တစ်ခုတည်းနဲ့မပြီးပါ။ Home, Detail, Profile, Settings စတဲ့ page တွေကြားသွားလာရပါတယ်။ Flutter မှာ Navigator ကိုသုံးပြီး screen stack ကိုစီမံပါတယ်။ push က screen အသစ်တင်တာ၊ pop က လက်ရှိ screen ကိုဖယ်ပြီးနောက်ပြန်တာပါ။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Navigator.push() ကို MaterialApp မရှိတဲ့ context မှာခေါ်ရင် route ဆိုင်ရာ error ဖြစ်နိုင်ပါတယ်။ App root မှာ MaterialApp ထားပါ။
ဖြစ်လေ့ရှိတဲ့အမှား
Screen တစ်မျိုးတွင် sample output မှန်ရုံဖြင့် rebuild, overflow, accessibility, async နဲ့ lifecycle paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Basic Navigation ကို UI, domain, data source နဲ့ failure state ခွဲထားသော flow အဖြစ်တည်ဆောက်ပါ။ Loading, empty, success, error, retry, cancellation နဲ့ route restoration behavior ကိုရှင်းလင်းစွာကိုင်တွယ်ပါ။
- Route / gesture
- Navigator
- Screen + result
Basic Navigation ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
// First screen မှာ
ElevatedButton(
child: const Text('Go to Details'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DetailScreen(),
),
);
},
)
// Detail screen မှာ
ElevatedButton(
child: const Text('Go Back'),
onPressed: () {
Navigator.pop(context);
},
)Basic Navigation ကို UI, domain, data source နဲ့ failure state ခွဲထားသော flow အဖြစ်တည်ဆောက်ပါ။ Loading, empty, success, error, retry, cancellation နဲ့ route restoration behavior ကိုရှင်းလင်းစွာကိုင်တွယ်ပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Route / gesture
// First screen မှာMobile app တစ်ခုမှာ screen တစ်ခုတည်းနဲ့မပြီးပါ။ Home, Detail, Profile, Settings စတဲ့ page တွေကြားသွားလာရပါတယ်။ Flutter မှာ Navigator ကိုသုံးပြီး screen stack ကိုစီမံပါတယ်။ push က screen အသစ်တင်တာ၊ pop က လက်ရှိ screen ကိုဖယ်ပြီးနောက်ပြန်တာပါ။
- Navigator
);Basic Navigation ကို UI, domain, data source နဲ့ failure state ခွဲထားသော flow အဖြစ်တည်ဆောက်ပါ။ Loading, empty, success, error, retry, cancellation နဲ့ route restoration behavior ကိုရှင်းလင်းစွာကိုင်တွယ်ပါ။
- Screen + result
)Basic Navigation example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။
- Route / gesture
- Navigator
- Screen + result
Success
Basic Navigation ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
Failure
Navigator.push() ကို MaterialApp မရှိတဲ့ context မှာခေါ်ရင် route ဆိုင်ရာ error ဖြစ်နိုင်ပါတယ်။ App root မှာ MaterialApp ထားပါ။
Mobile app တစ်ခုမှာ screen တစ်ခုတည်းနဲ့မပြီးပါ။ Home, Detail, Profile, Settings စတဲ့ page တွေကြားသွားလာရပါတယ်။ Flutter မှာ Navigator ကိုသုံးပြီး screen stack ကိုစီမံပါတယ်။ push က screen အသစ်တင်တာ၊ pop က လက်ရှိ screen ကိုဖယ်ပြီးနောက်ပြန်တာပါ။
// First screen မှာ
ElevatedButton(
child: const Text('Go to Details'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DetailScreen(),
),
);
},
)
// Detail screen မှာ
ElevatedButton(
child: const Text('Go Back'),
onPressed: () {
Navigator.pop(context);
},
)Go to Details နှိပ်ရင် DetailScreen သို့သွားပြီး Go Back နှိပ်ရင် Home screen သို့ပြန်လာပါမယ်။နောက်တစ်ဆင့်
Page များလာရင် route name နဲ့စီမံဖို့ Named Routes ကိုဆက်သင်ပါ။
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Basic Navigation 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
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Basic Navigation 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 ကိုခန့်မှန်းပါ
// First screen မှာ
ElevatedButton(
child: const Text('Go to Details'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DetailScreen(),
),
);
},
)
// Detail screen မှာ
ElevatedButton(
child: const Text('Go Back'),
onPressed: () {
Navigator.pop(context);
},
)ရလဒ်: Basic Navigation ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Basic Navigation 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
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Route / gesture → Navigator → Screen + result
- Basic Navigation ကို UI, domain, data source နဲ့ failure state ခွဲထားသော flow အဖြစ်တည်ဆောက်ပါ။ Loading, empty, success, error, retry, cancellation နဲ့ route restoration behavior ကိုရှင်းလင်းစွာကိုင်တွယ်ပါ။
- Navigator.push() ကို MaterialApp မရှိတဲ့ context မှာခေါ်ရင် route ဆိုင်ရာ error ဖြစ်နိုင်ပါတယ်။ App root မှာ MaterialApp ထားပါ။
- Basic Navigation 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