Flutter文本左对齐

11

我试图将所有文本向左对齐。但是,如下面的图像所示,它总是在中间。我尝试使用 Align 组件,并将 Text 组件的 textAlign 属性设置为 TextAlign.left,但没有成功。

enter image description here

card.dart

Row(
  children: <Widget>[
    Card(
      elevation: 2,
      child: ClipRRect(
        borderRadius: BorderRadius.all(Radius.circular(4)),
        child: Image.network('https://loremflickr.com/100/100'),
      ),
    ),
    Padding(
      padding: const EdgeInsets.only(left: 8),
      child: Column(
        children: <Widget>[
          Align(
            alignment: Alignment.centerLeft,
            child: Text(
              'Marry Jane',
              textAlign: TextAlign.left,
              style: TextStyle(fontSize: 16),
            ),
          ),
          Align(
            alignment: Alignment.centerLeft,
            child: Text(
              'Make-up Artist',
              textAlign: TextAlign.left,
              style: TextStyle(fontSize: 14, color: Color(0xff666666)),
            ),
          ),
          Row(
            children: <Widget>[
              Text(
                '3.5',
                textAlign: TextAlign.left,
                style: TextStyle(fontSize: 18, color: Color(0xff666666)),
              ),
              Icon(FontAwesomeIcons.starHalf)
            ],
          )
        ],
      ),
    )
  ],
),
1个回答

40

你尝试过将Column的CrossAxisAlignment设置为start吗?

    Row(
      children: <Widget>[
        Card(
          elevation: 2,
          child: ClipRRect(
            borderRadius: BorderRadius.all(Radius.circular(4)),
            child: Image.network('https://loremflickr.com/100/100'),
          ),
        ),
        Padding(
          padding: const EdgeInsets.only(left: 8),
          child: Column(
            /// Add this
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text(
                'Marry Jane',
                style: TextStyle(fontSize: 16),
              ),
              Text(
                'Make-up Artist',
                style: TextStyle(fontSize: 14, color: Color(0xff666666)),
              ),
              Text(
                '3.5',
                style: TextStyle(fontSize: 18, color: Color(0xff666666)),
              ),
            ],
          ),
        )
      ],
    )

1
它能工作,但我不明白为什么它的中心默认值。我习惯于Android布局,有时会遇到困难,谢谢。 - Burak
1
另外,您可以清除所有的对齐和文本对齐方式。我已经编辑了答案。 - Federick Jonathan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接