如何使用MaterialPageRoute?添加Pagetransitiontype时使用时遇到问题。我的代码:
class Program extends State<Portao> {
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: CurvedNavigationBar(
index: 0,
height: 50.0,
items: <Widget>[
Icon(Icons.home, size: 30, color: Colors.black), //0
Icon(Icons.camera_alt, size: 30, color: Colors.black), //1
Icon(Icons.build, size: 30, color: Colors.black), //2
],
...
),
onTap: (index) {
if (index==1)
Navigator.push(
context,
PageTransition(
type: PageTransitionType.rightToLeft,
(/*erro*/)child: MaterialPageRoute(builder: (context) => Camera());
),
);
else if (index==2)
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Definicoes()),
);},)
答案 0 :(得分:1)
如果您使用的是page_transition
插件,请使用以下代码
if (index==1)
Navigator.push(
context,
PageTransition(
type: PageTransitionType.rightToLeft,
child: Camera());
}
这是bottomNavigationBar
bottomNavigationBar: CurvedNavigationBar(
index: 0,
height: 50.0,
items: <Widget>[
Icon(Icons.home, size: 30, color: Colors.black), //0
Icon(Icons.camera_alt, size: 30, color: Colors.black), //1
Icon(Icons.build, size: 30, color: Colors.black), //2
],
onTap: (index) {
if (index == 1) {
Navigator.push(
context,
PageTransition(
type: PageTransitionType.rightToLeft, child: Camera()));
} else if (index == 2) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Camera()),
);
}
}),