Flutter-GridView不滚动-底部溢出

时间:2020-06-19 04:56:03

标签: flutter gridview scroll

我有一个GridView,其底部溢出如下。

enter image description here

我尝试了很多方法,包括在GridView中添加ScrollPhysics(),将GridView包裹在Expanded窗口小部件中,或将Container包裹在Expanded窗口小部件中。 以上都不是。有人可以请指教吗?

下面是我的代码:

Widget portfolioRow = StreamBuilder(
  stream: Firestore.instance.collection('portfolio').snapshots(),
  builder: (context, snapshot) {
    if (!snapshot.hasData) return Text("Loading...");
    return GridView.builder(
        physics: ScrollPhysics(),
        shrinkWrap: true,
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 3,
          crossAxisSpacing: 70.0,
          mainAxisSpacing: 70.0,
        ),
        itemCount: snapshot.data.documents.length,
        itemBuilder: (context, index) =>
            portfolioContainer(context, snapshot.data.documents[index]));
    },
);

Widget portfolioContainer(
    BuildContext context, DocumentSnapshot documentSnapshot) {
  return Container(
    height: 500,
    width: 302,
    decoration: myPortfolioDecoration(),
    child: Column(children: [
      Container(
        margin: const EdgeInsets.only(top: 20, bottom: 10),
        width: 250,
        height: 250,
        decoration: myPortfolioDecoration(),
      ),
      Container(
          height: 3,
          width: 30,
          margin: const EdgeInsets.only(top: 15, bottom: 20, right: 210),
          decoration: BoxDecoration(color: Colors.yellow)),
      Container(
        padding: const EdgeInsets.only(bottom: 10, left: 30),
        alignment: Alignment.centerLeft,
        child: Text.rich(
          TextSpan(
              text: documentSnapshot.data["title"],
              style: Theme.of(context).textTheme.headline5),
        ),
      ),
      Container(
        padding: const EdgeInsets.only(left: 30, bottom: 20),
        alignment: Alignment.centerLeft,
        child: Text.rich(
          TextSpan(
              text: documentSnapshot.data["tagline"],
              style: Theme.of(context).textTheme.bodyText1),
        ),
      ),
    ]),
  );
}

1 个答案:

答案 0 :(得分:0)

我通过添加aes(width=...some log10 transformation...)成功摆脱了底部溢出:

childAspectRatio