以下是布局不正确的屏幕截图:
正如你在上面看到的,一行中的一列正在推动其他孩子。
我已经从行中删除了列,并且布局按预期显示。但是,我需要该列成为行的一部分。
class TitleSection extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return Container(
padding: EdgeInsets.all(32),
child: Row(
children: <Widget>[
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Kratos",style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20
)),
Text("The God Of War",
style: TextStyle(
color: Colors.grey[500]
),
),
],
),
),
Icon(
Icons.star,
color: Colors.red,
),
Text("143")
],
)
);
}
}
与其将您的Column
with包裹起来,Expanded
这将占用尽可能多的空间Flexible
,还可以将其他小部件包裹在 a 中,Column
以便您可以轻松地布置它们:
class TitleSection extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.all(32),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Kratos",style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20
)),
Text("The God Of War",
style: TextStyle(
color: Colors.grey[500]
),
),
],
),
),
Flexible(
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Icon(
Icons.star,
color: Colors.red,
),
Text("143")
],
),
],
),
),
],
)
);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句