flutter - 如何使 FloatingActionButton 在 persistentFooterButtons 中居中

标签 flutter flutter-layout

有人可以向我解释如何将 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/

相关文章:

dart - dart 中的 throttle 函数执行

flutter - 如何在 flutter 中对齐定位小部件内的文本?

flutter - 如何在 flutter 中制作这个气泡类型的小部件来描述点击时的特定消息?

flutter - 为 Row 中的所有 child 设置相同的大小

flutter - 调用函数时 (_) 是什么意思?

firebase - flutter Firebase Admob : AdView not Destroy on Page Navigation

flutter - 如何解决 Dart 的 future ?

dart - 命名参数 'home' 未定义 Flutter

flutter - Flutter 中的动 Canvas 局变化

flutter - Flutter在GridView下方添加容器