有人可以向我解释如何将 FloatingActionButton 置于 persistentFooterButtons 中。我在这里遗漏了一些东西。
List _footer() {
return <Widget>[
new ButtonBar(
children: <Widget>[
new Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new FloatingActionButton(
backgroundColor: Colors.redAccent,
onPressed: () => {},
),
],
),
)
],
)
];}
===
@override Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Question"),
),
body: _body(),
persistentFooterButtons: _footer(),
); }
最佳答案
我查看了 Scaffold 的代码,下面是 persistentFooterButtons 是如何创建的:
new Container(
decoration: new BoxDecoration(
border: new Border(
top: Divider.createBorderSide(context, width: 1.0),
),
),
child: new SafeArea(
child: new ButtonTheme.bar(
child: new SafeArea(
top: false,
child: new ButtonBar(
children: widget.persistentFooterButtons
),
),
),
),
)
你可以在这里看到,你的按钮被一个 ButtonBar 包裹着。现在让我们看看下面的 ButtonBar 代码,默认对齐方式是 MainAxisAlignment.end。我想这遵循了 Material 指南。
const ButtonBar({
Key key,
this.alignment: MainAxisAlignment.end,
this.mainAxisSize: MainAxisSize.max,
this.children: const <Widget>[],
}) : super(key: key);
Flutter 框架正在更新,但是直到今天(2018 年6 月8 日),您还不能使用persistentFooterButtons 将按钮放在中心。
解决方案:我建议你按照我的回答here将按钮放在屏幕的中央底部。
关于flutter - 如何使 FloatingActionButton 在 persistentFooterButtons 中居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50754979/