在多个项目之间分配空间

在多个项目之间分配空间

我正在尝试添加一张图像,该图像覆盖屏幕的顶部20%,其他 80%应该是一副纸牌。图片必须在正文中,并且不在Appbar的上。我制作了卡的网格,然后尝试将图像和网格放在一列中。实现如下。

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        primary: true,
        appBar: AppBar(
        elevation: 4.0,
        backgroundColor: Color(0xfff8f8f8),
        title: Center(child: titleLogo,),
        ),
  //------------ PROBLEM BELOW ----------------
        body: new Column(
          children: <Widget>[
            titleLogo,   //Image object
            TheGridView().build()  //Returns a GridView object
            ],
      ),
  ),
);

}

我收到以下错误
I/flutter (21751): The following assertion was thrown during performResize():
I/flutter (21751): Vertical viewport was given unbounded height.
I/flutter (21751): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter (21751): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter (21751): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter (21751): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter (21751): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter (21751): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter (21751): the height of the viewport to the sum of the heights of its children.

任何建议都将受到高度赞赏。先感谢您。

最佳答案

为了在多个项目之间分配空间,您应该使用Expanded小部件,如下所示:

return new Column(
  children: <Widget>[
    new Expanded(
      flex: 2,
      child: new Container(
        color: Colors.red,
      ),
    ),
    new Expanded(
      flex: 8,
      child: new Container(//use your Gridview instead
        color: Colors.green,
      )
    )
  ],

);

dart - 如何在多个项目之间分配空间-LMLPHP

09-26 20:23