參考資料:
Flutter里一個頁面導(dǎo)航到另一個頁面調(diào)用的Api是
一、iOS上Push/Pop效果
1.1 push操作
// 在iOS上默認效果是從右側(cè)推出一個新頁面,
//同時支持在屏幕左側(cè)右滑關(guān)閉頁面
//默認在push出的新頁面的導(dǎo)航欄左側(cè)有個返回箭頭的按鈕,點擊會返回上一個頁面
// 方式一
Navigator.of(context).push(
MaterialPageRoute(builder: (context) {
return SecondPage();
})
);
// 方式二
Navigator.push(context,
MaterialPageRoute(fullscreenDialog: true,
builder: (context) {
return SecondPage();
})
);
1.2 pop操作
// 在iOS向右畫出頁面
// 方式一
Navigator.of(context).pop();
//方式二
//Navigator.pop(context);
二、iOSpresent/dismiss效果
2.1 present操作
// 和Push、pop的操作一樣,只是在Push時設(shè)置fullscreenDialog為true
// 方式一
Navigator.of(context).push(
MaterialPageRoute(
fullscreenDialog: true,
builder: (context) {
return SecondPage();
}
)
);
// 方式二
Navigator.push(context,
MaterialPageRoute(
fullscreenDialog: true,
builder: (context) {
return SecondPage();
})
);
2.2 dismiss操作
// 和上面的POP完全一樣
// 方式一
Navigator.of(context).pop();
//方式二
//Navigator.pop(context);