ရိုးရိုးလေး ရှင်းပြမယ်
Named Routes ကို ရိုးရိုးလေးနားလည်မယ်
Named Routes ဆိုတာ screen တွေကို string name နဲ့မှတ်ထားတဲ့ navigation နည်းလမ်းပါ။ Page အနည်းငယ်ပဲရှိတဲ့ project မှာ direct MaterialPageRoute ကရိုးရှင်းပေမဲ့ route များလာရင် '/profile', '/settings', '/details' ဆိုပြီး central place တစ်ခုမှာသတ်မှတ်ထားတာ ပိုရှင်းပါတယ်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
routes ထဲမှာမရှိတဲ့ name ကို pushNamed ခေါ်ရင် route not found error ဖြစ်တတ်ပါတယ်။
ဖြစ်လေ့ရှိတဲ့အမှား
Screen တစ်မျိုးတွင် sample output မှန်ရုံဖြင့် rebuild, overflow, accessibility, async နဲ့ lifecycle paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Named Routes ကို UI, domain, data source နဲ့ failure state ခွဲထားသော flow အဖြစ်တည်ဆောက်ပါ။ Loading, empty, success, error, retry, cancellation နဲ့ route restoration behavior ကိုရှင်းလင်းစွာကိုင်တွယ်ပါ။
- Route / gesture
- Navigator
- Screen + result
Named Routes ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
MaterialApp(
initialRoute: '/',
routes: {
'/': (context) => const HomeScreen(),
'/details': (context) => const DetailScreen(),
'/settings': (context) => const SettingsScreen(),
},
);
// Navigate to settings
Navigator.pushNamed(context, '/settings');
// Go back
Navigator.pop(context);Named Routes ကို UI, domain, data source နဲ့ failure state ခွဲထားသော flow အဖြစ်တည်ဆောက်ပါ။ Loading, empty, success, error, retry, cancellation နဲ့ route restoration behavior ကိုရှင်းလင်းစွာကိုင်တွယ်ပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Route / gesture
MaterialApp(Named Routes ဆိုတာ screen တွေကို string name နဲ့မှတ်ထားတဲ့ navigation နည်းလမ်းပါ။ Page အနည်းငယ်ပဲရှိတဲ့ project မှာ direct MaterialPageRoute ကရိုးရှင်းပေမဲ့ route များလာရင် '/profile', '/settings', '/details' ဆိုပြီး central place တစ်ခုမှာသတ်မှတ်ထားတာ ပိုရှင်းပါတယ်။
- Navigator
},Named Routes ကို UI, domain, data source နဲ့ failure state ခွဲထားသော flow အဖြစ်တည်ဆောက်ပါ။ Loading, empty, success, error, retry, cancellation နဲ့ route restoration behavior ကိုရှင်းလင်းစွာကိုင်တွယ်ပါ။
- Screen + result
Navigator.pop(context);Named Routes 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
Named Routes ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
Failure
routes ထဲမှာမရှိတဲ့ name ကို pushNamed ခေါ်ရင် route not found error ဖြစ်တတ်ပါတယ်။
Named Routes ဆိုတာ screen တွေကို string name နဲ့မှတ်ထားတဲ့ navigation နည်းလမ်းပါ။ Page အနည်းငယ်ပဲရှိတဲ့ project မှာ direct MaterialPageRoute ကရိုးရှင်းပေမဲ့ route များလာရင် '/profile', '/settings', '/details' ဆိုပြီး central place တစ်ခုမှာသတ်မှတ်ထားတာ ပိုရှင်းပါတယ်။
MaterialApp(
initialRoute: '/',
routes: {
'/': (context) => const HomeScreen(),
'/details': (context) => const DetailScreen(),
'/settings': (context) => const SettingsScreen(),
},
);
// Navigate to settings
Navigator.pushNamed(context, '/settings');
// Go back
Navigator.pop(context);Navigator.pushNamed(context, '/settings') ခေါ်လိုက်ရင် SettingsScreen ပေါ်လာပါမယ်။နောက်တစ်ဆင့်
Navigation ပြီးရင် app ထဲမှာ image/file အသုံးပြုဖို့ Assets lesson ကိုဆက်ဖတ်ပါ။
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Named Routes 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
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Named Routes 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 ကိုခန့်မှန်းပါ
MaterialApp(
initialRoute: '/',
routes: {
'/': (context) => const HomeScreen(),
'/details': (context) => const DetailScreen(),
'/settings': (context) => const SettingsScreen(),
},
);
// Navigate to settings
Navigator.pushNamed(context, '/settings');
// Go back
Navigator.pop(context);ရလဒ်: Named Routes ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Named Routes 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
- Named Routes ကို UI, domain, data source နဲ့ failure state ခွဲထားသော flow အဖြစ်တည်ဆောက်ပါ။ Loading, empty, success, error, retry, cancellation နဲ့ route restoration behavior ကိုရှင်းလင်းစွာကိုင်တွယ်ပါ။
- routes ထဲမှာမရှိတဲ့ name ကို pushNamed ခေါ်ရင် route not found error ဖြစ်တတ်ပါတယ်။
- Named Routes 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