【发布时间】:2019-09-13 07:08:14
【问题描述】:
每当我使用 FlatButton 时,onPressed 方法在定位的小部件中不起作用。
我正在设计一个屏幕,按钮始终位于屏幕底部,单击该按钮我们可以移动到其他屏幕,但在这里它不起作用,任何人都可以检查并帮助我。提前谢谢
child: Stack(
// height: MediaQuery.of(context).size.height,
children: <Widget>[
Positioned(
left: 0,
bottom: 0,
// alignment: Alignment(0, 0),
child: Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
SizedBox(height: 115),
ButtonTheme(
minWidth:
MediaQuery.of(context).size.width / 2,
height: 60.0,
child: FlatButton.icon(
icon: Icon(FontAwesomeIcons.fileInvoice),
color: Colors.white,
onPressed: () {
MaterialPageRoute(builder: (context) => MainScreen());
},
label: Text(
"My Orders",
textAlign: TextAlign.center,
style: TextStyle(
// decoration: TextDecoration.underline,
fontSize: 25,
fontWeight: FontWeight.bold,
color: Theme.of(context).accentColor,
),
),
),
),
SizedBox(height: 115),
ButtonTheme(
minWidth:
MediaQuery.of(context).size.width / 2,
height: 60.0,
child: FlatButton.icon(
icon: Icon(FontAwesomeIcons.dollarSign),
color: Colors.white60,
onPressed: () {
Navigator.pushReplacementNamed(
context, '/home');
},
label: Text(
"Bean Balnace",
textAlign: TextAlign.center,
style: TextStyle(
// decoration: TextDecoration.underline,
fontWeight: FontWeight.bold,
fontSize: 20,
color: Theme.of(context).accentColor,
),
),
),
),
],
)),
【问题讨论】:
-
您遇到任何错误?
-
不,只是 onPressed 不起作用...
-
两个按钮都不起作用吗?
-
是的,两者都不起作用
-
只要 MainScreen() 存在并且您已经设置了 /home 路由,它就应该可以工作。您确定调试控制台中没有任何错误吗?
标签: flutter dart flutter-layout