首页 > 解决方案 > 如何在persistentFooterButtons中居中FloatingActionButton

问题描述

有人可以向我解释如何将 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(),
);  }

标签: flutterflutter-layout

解决方案


我发现一个简单的解决方案是将 FloatingActionButton 包装在与屏幕宽度相同的大小框中。

      persistentFooterButtons: <Widget>[
        SizedBox(
          width: MediaQuery.of(context).size.width,
          child: FloatingActionButton(

            onPressed: () {
              print('Close pressed');
            },
            child: Text('Close'),
          )
        )
      ],

推荐阅读