之间的空间不起作用,我做错了什么吗?

时间:2019-04-11 06:48:35

标签: dart flutter

用于迁移图像https://lh3.googleusercontent.com/sTFx8QfUzgnrT69cK54V9igmCd04GLIlTmrwAC01GISRDsbGNL9KZeXNnKeILHdNUQ=w1853-h942

的应用

我在做什么
enter image description here

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")],
              )
            ],
          )
        ],
      ),
    );
  }
}

2 个答案:

答案 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")],
      )
    ],
  ),
)

这将产生以下输出:

enter image description here

答案 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来告诉您如何划分剩余区域的占用率