Flutter在开始时将两个文本垂直对齐

时间:2019-11-06 18:52:41

标签: flutter dart

我在这里有些困惑,但是我试图在Flutter中垂直对齐两个文本小部件,但是无论我做什么,文本都将以较少的文本居中。我试图获取“地址”标题和实际地址都垂直于行顶部,但由于实际地址较长,因此始终将地址标题居中(在下面的图像地址居中于第一个作业的中心)列表)。

enter image description here

这是我正在使用的代码:

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。从行开始,但是行不通...任何想法吗?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

我不确定我确切地了解您要做什么,但也许您想使用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),
                  ),
                ],
              ),
            ),
          ),
        ],
      )