如何按照Material Design规范在Flutter中居中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.
相关产品推荐
相关产品推荐

