flutter - 网格视图不显示在展开的小部件中。

问题描述 投票:0回答:1

我试图显示一个GridView,它应该填满整个剩余的空间。GridView工作得很完美,但当我试图用 "扩展 "widget包裹它时,只有当把它包裹在一个SizedBox中时,才会不显示。我的Screen只是一个带有这个主体的Saffold。

body: Column(
            children: <Widget>[
              //recent classifications
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: Theme.of(context).accentColor,
                    borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(30.0),
                      topRight: Radius.circular(30.0),
                    ),
                  ),
                  child: Column(
                    children: <Widget>[
                      CategorySelector(),
                    ],
                  ),
                ),
              ),
            ],
          ),

CategorySelector' widget显示我的GridView。

Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Padding(
            padding: EdgeInsets.symmetric(
              horizontal: 20.0,
              vertical: 0,
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  "GridView",
                  style: TextStyle(
                    fontSize: 20.0,
                    fontWeight: FontWeight.bold,
                    letterSpacing: 1.0,
                  ),
                ),
                IconButton(
                  icon: Icon(Icons.more_horiz),
                  onPressed: () {},
                ),
              ],
            ),
          ),
        SizedBox(
          height: 500,
                  child: GridView.builder(
            padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
            gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
              crossAxisCount: 2,
              childAspectRatio: 2 / 3,
              crossAxisSpacing: 20,
              mainAxisSpacing: 30,
            ),
            itemBuilder: (BuildContext context, int index) {
              return Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(30),
                  border: Border.all(
                    width: 3,
                    color: Theme.of(context).primaryColor,
                  ),
                ),
                child: GridTile(
                  child: Image.asset(bones.bones[index].imageUrl),
                  footer: GridTileBar(
                    title: Padding(
                      padding: EdgeInsets.only(top: 15),
                      child: Text(
                        bones.bones[index].title,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            color: Theme.of(context).primaryColor,
                            fontWeight: FontWeight.bold,
                            fontSize: 18),
                      ),
                    ),
                    backgroundColor: Colors.transparent,
                    subtitle: Text(
                      bones.bones[index].id,
                      style: TextStyle(color: Colors.black),
                    ),
                  ),
                ),
              );
            },
            itemCount: bones == null ? 0 : bones.bones.length,
          ),
        ),
      ],
    );
  }

当在一个展开的widget中构建它时,会抛出以下错误。NEEDS LAYOUT NEEDS PAINT.

我到底做错了什么?

flutter dart flutter-layout
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.