全角按钮,如何对齐文本 [英] Full width button, how to align text

查看:69
本文介绍了全角按钮,如何对齐文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试找出是否可以在全角按钮(即具有宽度的按钮)中对齐文本:double.infinity

Trying to figure out if I can align the text in a full width button, i.e a button that has width: double.infinity

例如:

ButtonTheme(
  minWidth: double.infinity,
  child: FlatButton(
    onPressed: () {},
    child: Text('Sign Out', textAlign: TextAlign.left),
  ),
)

产生一个居中的文本按钮,并且对齐方式无法更改。

produces a centered text button and the alignment cannot be changed.

我尝试了一些操作,但除非我尝试创建自定义按钮,否则无法弄清。

I have tried a few things but can't figure it out, unless I try to create a custom button.

我正在尝试获得完整宽度带有文本的按钮:向左,以便用户可以在行中的任何位置单击,并仍然获得实质的点击效果。

I'm trying to get a full width button with text:left so the user can click anywhere in the row, and still get the material tap effect.

推荐答案

我发现 RawMaterialButton 的埠ild-方法孩子是始终居中

I found out that RawMaterialButton's build-Method the child is always centered:

child: Center(
  widthFactor: 1.0,
  heightFactor: 1.0,
  child: widget.child,
),

对齐到开始/左边,您可以给它一个无限的宽度,这将使其与它的父中心小部件一样宽。

To have the text to be aligned to start/left you could give it an infinite width, which would make it as wide as its parent, the Center widget.

child: FlatButton(
  child: SizedBox(
    width: double.infinity,
    child: Text(
      'Sign out',
      textAlign: TextAlign.left,
    ),
  ),
  onPressed: () {},
);

这篇关于全角按钮,如何对齐文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆