class ScheduleListItem extends StatelessWidget {
ScheduleListItem({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
height: 300,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.black26, offset: Offset(0, 5), blurRadius: 5)
]),
margin: EdgeInsets.all(7),
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
width: 15,
decoration: BoxDecoration(
color: Colors.red,
borderRadius:
BorderRadius.horizontal(left: Radius.circular(10))),
),
Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween ,
children: <Widget>[Text("Data"), Text("Data")],
),
Row(
children: <Widget>[Text("Data"), Text("Data")],
),
Row(
children: <Widget>[Text("Data"), Text("Data")],
)
],
)
],
),
);
}
}
答案 0 :(得分:1)
我假设您想将两个Text
小部件放在一行中。
如果是这样,您的列就不会占用整个水平空间。您可以将其包装到Expanded
小部件中,如下所示:
Expanded(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[Text("Data"), Text("Data")],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[Text("Data"), Text("Data")],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[Text("Data"), Text("Data")],
)
],
),
)
这将产生以下输出:
答案 1 :(得分:1)
您需要将Column
包装在Expanded
中,然后才能使用Spacer
属性,它将占用剩余的空间。
Expanded(
child: Column(
children: <Widget>[
Row(children: <Widget>[Text("Data"), Spacer(), Text("Data")]),
Row(children: <Widget>[Text("Data"), Spacer(), Text("Data")]),
Row(children: <Widget>[Text("Data"), Spacer(), Text("Data")])
],
),
)
如果flex
中有多个Spacer
,您还可以使用Spacer
中的Row/Column
来告诉您如何划分剩余区域的占用率>