我正在尝试构建一个返回一些按钮的应用程序,但是当我从另一个类中返回按钮时,它们将失去所有的填充和对齐方式。
例如,此代码创建了5个位于屏幕底部的按钮:
Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 11.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.undo),
splashColor: Colors.pink[900],
backgroundColor: Colors.pink[250],
),
FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.cancel),
splashColor: Colors.pink[900],
backgroundColor: Colors.pink[250],
),
FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.favorite),
splashColor: Colors.pink[900],
backgroundColor: Colors.pink[250],
),
FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.check_circle),
splashColor: Colors.pink[900],
backgroundColor: Colors.pink[250],
),
FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.share),
splashColor: Colors.pink[900],
backgroundColor: Colors.pink[250],
),
],
),
),
],
);
但是,如果我从另一个.dart文件返回此代码,就像这样:
Widget build(BuildContext context) {
_controller.forward();
return FadeTransition(
opacity: _animation,
child: Column(
children: <Widget>[
SurpriseImage(),
],
),
);
}
这些按钮最终显示在屏幕顶部。
为什么会这样?
MainAxisAlignment.end将仅确保按钮位于Column Widget的末尾,但没有确保此Widget到达屏幕的底部