You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何按照Material Design规范在Flutter中居中Extended FAB?

Extended FAB

如何按照Material Design规范将Flutter中的Extended FAB居中显示?

当前Extended FAB处于右对齐状态,代码示例如下:

new Scaffold(
  floatingActionButton: new FloatingActionButton.extended(
    onTap: () => {},
    label: new Text('See all results')
  )
)

其实解决这个问题超简单,Flutter的Scaffold组件专门提供了floatingActionButtonLocation属性来控制FAB的位置,我们只需要把它设置为FloatingActionButtonLocation.centerFloat,就能让Extended FAB完全符合Material Design规范居中显示了。

修改后的完整代码如下:

Scaffold(
  floatingActionButton: FloatingActionButton.extended(
    onTap: () => {},
    label: const Text('See all results'),
  ),
  floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
)

要是之后你需要更个性化的位置,还可以试试FloatingActionButtonLocation的其他预设值,甚至自定义位置实现,但centerFloat已经完全满足Material Design里居中Extended FAB的标准要求啦。

内容的提问来源于stack exchange,提问作者S.D.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:18:30