Flutter - 在行内使用多行标签

11

布局定义如下:

 var cardLayout = Flexible(
              child: new Container(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Padding(
                      child: Row(children: <Widget>[
                        Text(categoryIcon,style: TextStyle(color: Colors.lightBlue, fontFamily: 'Fontawesome', fontWeight: FontWeight.normal)),
                        Text("   " + categoryName, maxLines: 3, style: TextStyle(color: Colors.lightBlue, fontWeight: FontWeight.normal)) //Overflow!!
                      ]),
                      padding: EdgeInsets.only(bottom: 10.0,left: 10.0, top: 10.0),
                    ),
                    Padding(
                      child: Text(title, maxLines: 3, overflow: TextOverflow.ellipsis, style: TextStyle(fontWeight: FontWeight.normal, fontSize: 16)),
                      padding: EdgeInsets.only(bottom: 10.0,left: 10.0, top: 10.0),
                    ),
                    Padding(
                      child: new Text(address, style: TextStyle(fontStyle: FontStyle.normal)),
                      padding: EdgeInsets.only(bottom: 15.0,left: 10.0, top: 10.0),
                    ),

                    Visibility(
                    child: Padding(
                      child: new Text("⬤   " + statusName, style: TextStyle(fontStyle: FontStyle.normal,color:HexColor(statusColor))),
                      padding: EdgeInsets.only(bottom: 15.0,left: 10.0, top: 10.0),
                    ),
                      visible: type == ResponseMessageType.MESSAGE_TYPE_EVENT|| type == ResponseMessageType.MESSAGE_TYPE_MY_EVENT,
                    )
                  ],
                ),
              )
          );

我不明白为什么类别标签不是多行显示。它溢出了(我在粘贴的代码中添加了注释以显示我指的哪个标签)。似乎问题出在行上。如何保留行,但使标签多行显示?

1个回答

47

Text小部件简单包装在Flexible中,使其成为多行文本小部件。

 Flexible(
                child: Text("   " + categoryName,
                    maxLines: 3,
                    style: TextStyle(
                        color: Colors.lightBlue,
                        fontWeight: FontWeight.normal)),
              ),

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