Mobile app တစ်ခုမှာ screen တစ်ခုတည်းနဲ့မပြီးပါ။ Home, Detail, Profile, Settings စတဲ့ page တွေကြားသွားလာရပါတယ်။ Flutter မှာ Navigator ကိုသုံးပြီး screen stack ကိုစီမံပါတယ်။ push က screen အသစ်တင်တာ၊ pop က လက်ရှိ screen ကိုဖယ်ပြီးနောက်ပြန်တာပါ။
dart
// 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);
},
)You should see
Go to Details နှိပ်ရင် DetailScreen သို့သွားပြီး Go Back နှိပ်ရင် Home screen သို့ပြန်လာပါမယ်။နောက်တစ်ဆင့်
Page များလာရင် route name နဲ့စီမံဖို့ Named Routes ကိုဆက်သင်ပါ။