Flutter 柱内不同排列的颤振
我有一列有三行:Flutter 柱内不同排列的颤振,flutter,flutter-layout,Flutter,Flutter Layout,我有一列有三行: @override Widget build(BuildContext context) { return GestureDetector( onTap: () { print('card of course clicked'); }, child: Card( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0)), child: Contai
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
print('card of course clicked');
},
child: Card(
shape: RoundedRectangleBorder(borderRadius:
BorderRadius.circular(8.0)),
child: Container(
height: 144,
child: Row(children: [
Padding(
padding: EdgeInsets.all(16.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
child: Image.network(_model._schoolThumb))),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 16),
Align(
alignment: Alignment.center,
child: Text(_model._schoolName,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 18)),
),
SizedBox(height: 12),
Row(
children: <Widget>[
Icon(Icons.location_on, color: Colors.grey[700]),
Container(width: 8),
Text(_model._guides,
style: TextStyle(
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.w400)),
],
),
SizedBox(height: 12),
Row(
children: <Widget>[
Icon(Icons.attach_money, color: Colors.grey[700]),
Container(width: 8),
Text(_model._priceFrom,
style: TextStyle(
fontSize: 14,
color: Colors.black,
fontWeight: FontWeight.w400))
],
)
],
)
]),
),
),
);
}
@覆盖
小部件构建(构建上下文){
返回手势检测器(
onTap:(){
打印(“当然点击卡片”);
},
孩子:卡片(
形状:圆角矩形边框(边框半径:
边界半径。圆形(8.0)),
子:容器(
身高:144,
子对象:行(子对象:[
填充物(
填充:所有边缘设置(16.0),
孩子:ClipRRect(
borderRadius:borderRadius.all(半径.圆形(8.0)),
孩子:Image.network(_model._schooltumb)),
纵队(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
尺寸箱(高度:16),
对齐(
对齐:对齐.center,
孩子:文本(_model._schoolName,
样式:TextStyle(
颜色:颜色,黑色,
fontWeight:fontWeight.w600,
尺寸:18),,
),
尺寸箱(高度:12),
划船(
儿童:[
图标(Icons.location\u on,颜色:Colors.grey[700]),
容器(宽度:8),
文本(_模型。_指南,
样式:TextStyle(
尺寸:14,
颜色:颜色,黑色,
fontWeight:fontWeight.w400),
],
),
尺寸箱(高度:12),
划船(
儿童:[
图标(Icons.attach_money,颜色:Colors.grey[700]),
容器(宽度:8),
文本(_model._priceFrom,
样式:TextStyle(
尺寸:14,
颜色:颜色,黑色,
fontWeight:fontWeight.w400)
],
)
],
)
]),
),
),
);
}
因此,我有三行对齐开始
如何对齐中间的第一个Text()
?为文本赋予属性并在扩展的、容器
、堆栈
中进行包装没有帮助,或者我做得不对。提前谢谢
编辑
整个build()
方法已附加更新
您没有为列指定宽度,因此它不知道可以采用的剩余宽度。因此,将你的专栏用一种灵活的方式包装起来,这样可以使它有足够的宽度来扩展
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 16),
Row(
灵活(
子:列(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
尺寸箱(高度:16),
划船(
问题:
默认情况下,列
的宽度
设置为列
中最宽的子
小部件的宽度
解决方案:
您需要使用扩展的或灵活的来包装列
如下图所示
Expanded(
child: Column(
children: <Widget>[
...
],
),
)
或
使用Align()小部件。颤振布局备忘单@RubensMelo使用Align包装文本help@TinusJackson谢谢,但我在文章中没有找到解决方案,在我的文章中效果很好…那么你的专栏受其父代的影响我有build()
method。我的意思是复制我的构建方法并尝试,但我有一个不同的父对象。即使它可以工作,如何在布局中使用它?parentdatawidget的使用不正确
Flexible(
child: Column(
children: <Widget>[
...
],
),
)
Align(
alignment: Alignment.center,
child: Text(
"Test",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 18,
),
),
),
Center(
child: Text(
"Test",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 18,
),
),
),