Flutter 使列';s子项(如容器布局)水平包装内容
如图所示:Flutter 使列';s子项(如容器布局)水平包装内容,flutter,Flutter,如图所示: 这两个文本之间有一条实线(神奇宝贝,上午11:25)我想要的是行的长度等于最长的文本长度。但行的行为类似于match\u parent 在Android Native中,我们可以使用垂直线性布局,并在水平方向设置Android:layout\u width=“wrap\u content”限制 在颤振中,我们只能在垂直方向上设置列mainAxisSize:mainAxisSize.min限制 我想问题是由于分隔器。当分隔符消失时,列的宽度为换行内容 实验如下: 容器( 颜色:颜
这两个文本之间有一条实线(神奇宝贝,上午11:25)我想要的是行的长度等于最长的文本长度。但行的行为类似于match\u parent 在Android Native中,我们可以使用垂直线性布局,并在水平方向设置Android:layout\u width=“wrap\u content”限制 在颤振中,我们只能在垂直方向上设置列mainAxisSize:mainAxisSize.min限制 我想问题是由于分隔器。当分隔符消失时,列的宽度为换行内容 实验如下:
容器(
颜色:颜色,红色,
边缘:边缘组。对称(水平:8.0),
子:列(
mainAxisSize:mainAxisSize.min,
儿童:[
容器(
边缘:边缘组。对称(垂直:8.0),
填充:所有边缘设置(4.0),
子:文本(
“神奇宝贝”,
样式:TextStyle(
颜色:颜色,白色,
字体大小:18.0,
fontWeight:fontWeight.bold),
maxLines:1,
溢出:TextOverflow.省略号,
),
),
分隔器(
身高:2.0,
颜色:颜色,白色,
),
容器(
页边距:仅限边缘集(顶部:8.0),
子:文本(
"上午十一时二十五分",,
样式:TextStyle(
颜色:颜色,白色,
字体大小:12.0,
fontWeight:fontWeight.bold),
maxLines:1,
溢出:TextOverflow.省略号,
),
),
],
),
),
您可以使用-IntrinsicWidth
小部件。用它包装列
Container(
color: Colors.red,
margin: EdgeInsets.symmetric(horizontal: 8.0),
child: IntrinsicWidth(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(vertical: 8.0),
padding: EdgeInsets.all(4.0),
child: Text(
'Pokémon',
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.bold),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
Divider(
height: 2.0,
color: Colors.white,
),
Container(
margin: EdgeInsets.only(top: 8.0),
child: Text(
'11.25 AM',
style: TextStyle(
color: Colors.white,
fontSize: 12.0,
fontWeight: FontWeight.bold),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
),
容器(
颜色:颜色,红色,
边缘:边缘组。对称(水平:8.0),
子:内部宽度(
子:列(
mainAxisSize:mainAxisSize.min,
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
容器(
边缘:边缘组。对称(垂直:8.0),
填充:所有边缘设置(4.0),
子:文本(
“神奇宝贝”,
样式:TextStyle(
颜色:颜色,白色,
字体大小:18.0,
fontWeight:fontWeight.bold),
maxLines:1,
溢出:TextOverflow.省略号,
),
),
分隔器(
身高:2.0,
颜色:颜色,白色,
),
容器(
页边距:仅限边缘集(顶部:8.0),
子:文本(
"上午十一时二十五分",,
样式:TextStyle(
颜色:颜色,白色,
字体大小:12.0,
fontWeight:fontWeight.bold),
maxLines:1,
溢出:TextOverflow.省略号,
),
),
],
),
),
),
您到底想要什么?我想要的是行的长度等于最长的文本长度。
Container(
color: Colors.red,
margin: EdgeInsets.symmetric(horizontal: 8.0),
child: IntrinsicWidth(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(vertical: 8.0),
padding: EdgeInsets.all(4.0),
child: Text(
'Pokémon',
style: TextStyle(
color: Colors.white,
fontSize: 18.0,
fontWeight: FontWeight.bold),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
Divider(
height: 2.0,
color: Colors.white,
),
Container(
margin: EdgeInsets.only(top: 8.0),
child: Text(
'11.25 AM',
style: TextStyle(
color: Colors.white,
fontSize: 12.0,
fontWeight: FontWeight.bold),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
],
),
),
),