我想在 BottomAppBar 的单击图标上导航到新屏幕,但出现错误:在初始化程序中只能访问静态成员
final makeBottom = Container(
height: 45.0,
child: BottomAppBar(
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(
icon: Icon(Icons.home, color: Color.fromARGB(255, 30, 110, 160)),
onPressed: navigateToPage,//only static members can be accessed in initializers
),
IconButton(
icon: Icon(Icons.search, color: Color.fromARGB(255, 30, 110, 160)),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.star, color: Color.fromARGB(255, 30, 110, 160)),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.favorite_border,
color: Color.fromARGB(255, 30, 110, 160)),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.account_circle,
color: Color.fromARGB(255, 30, 110, 160)),
onPressed: () {},
),
],
),
),
);
方法 navigateToPage
void navigateToPage() async {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Userqst(
user: widget.user,
),
fullscreenDialog: true));
}