【问题标题】:Flutter Align both texts at the start Vertically in a rowFlutter 将两个文本在开头垂直对齐
【发布时间】:2020-03-03 07:52:40
【问题描述】:

我在这里有点难过,但我试图在 Flutter 中将两个文本小部件在垂直开始处对齐,但无论我尝试做什么,文本都在文本小部件中居中,文本较少。我试图让“地址”标题和实际地址都从行的顶部垂直开始,但由于实际地址较长,它总是以地址标题为中心(在下图中,地址以第一份工作为中心)列表)。

这是我正在使用的代码:

Column(children: <Widget>[
                  Row(children: <Widget>[
                    Text('Status: ', style: TextStyle(fontWeight: FontWeight.bold),),
                    Text(job['status'])

                  ],),
                  Row(children: <Widget>[
                    Text('Engineer: ', style: TextStyle(fontWeight: FontWeight.bold),),
                    Flexible(child: Text(job['eng']))

                  ],),
                  Row(mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[
                    Text('Address: ', style: TextStyle(fontWeight: FontWeight.bold),),
                    Flexible(child: Text(job['address']))

                  ],)
                ],)

我已尝试在行上执行 mainaxisalignment.start,但它不起作用...任何想法吗?

【问题讨论】:

  • 您是要水平对齐还是垂直对齐?
  • 垂直,我完全搞砸了!

标签: flutter dart


【解决方案1】:

在您的Row 上尝试crossAxisAlignment: CrossAxisAlignment.start

【讨论】:

  • 意识到我在某些代码上犯了错误,这是正确的答案
【解决方案2】:

我不确定我明白你到底想做什么,但也许你想使用Column 而不是Row 用于地址和crossAxisAlignment

      Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            'Address: ',
            style: TextStyle(fontWeight: FontWeight.bold),
          ),
          Text(job['address'])
        ],
      )

或许

      Row(
        children: <Widget>[
          Flexible(
            child: RichText(
              text: TextSpan(
                text: 'Address: ',
                style: TextStyle(
                    fontWeight: FontWeight.bold, color: Colors.black),
                children: [
                  TextSpan(
                    text: '23 Test Street, Test City',
                    style: TextStyle(
                        fontWeight: FontWeight.normal,
                        color: Colors.black),
                  ),
                ],
              ),
            ),
          ),
        ],
      )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-17
    • 1970-01-01
    • 2016-02-21
    • 2013-07-28
    • 2015-05-04
    • 2016-03-30
    • 1970-01-01
    相关资源
    最近更新 更多