Flutter GridView 不滚动

标签 flutter dart gridview scroll flutter-layout

我正在 GridView 中添加标题。标题正在滚动,但在触摸 GridView 时。它没有滚动。我想滚动标题和 gridview。 我使用了 SingleChildScrollViewExpanded。如何解决请帮帮我。

我的代码如下所示

Widget ItemGridview() {
    return Container(
        color: Colors.white,
    padding: EdgeInsets.all(10),
    child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
            new Expanded(
            child: SingleChildScrollView(
            child: Column(
                children: <Widget>[
                new Text(
            'Items of products',
            style: TextStyle(fontWeight: FontWeight.w700, fontSize: 18.0),
            textAlign: TextAlign.left,
        ),
                GridView.count(
            shrinkWrap: true,
            primary: true,
            padding: EdgeInsets.only(top:15.0),
            crossAxisCount: 3,
            childAspectRatio: 0.60, //1.0
            mainAxisSpacing: 0.2, //1.0
            crossAxisSpacing: 4.0, //1.0
            children: createCategoryList(),
            ),
                ],
            ),
            )
        )
        ]
    ),
    );
}

在我的代码中,Items of products 是 header 。

List<Widget> createCategoryList() {

  List<Widget> createCategoryList = List<Widget>();

  for (int i = 0; i < documents.length; i++) {
    createCategoryList
        .add(makeGridCell(documents[i].data['title'], "name", 8,documents[i].data['id']));
  }
  return createCategoryList;
}

  Container makeGridCell(String name, String image, int count, String id) {
  return Container(

      child: new GestureDetector(
        onTap: () {
        },
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          mainAxisSize: MainAxisSize.min,
          verticalDirection: VerticalDirection.down,
          children: <Widget>[
            new Container(
              child: Image.asset('assets/' + image + ".jpg"),

            ),
            new Container(
              color: Colors.white,
              padding: EdgeInsets.only(left: 5),
              child: new Text(name,
                  style: TextStyle(
                      fontWeight: FontWeight.w500, fontSize: 18.0)), 
            ),

          ],
        ),
      ));
}

createCategoryList() 是用 widget 编写的网格中的项目列表。

最佳答案

我有像你一样的小部件树 包裹在 SingleChildScrollView 中的 gridview.count() 添加

physics: ScrollPhysics(),

GridView.count() Widget 解决了我的问题

来源:https://github.com/flutter/flutter/issues/19205

关于Flutter GridView 不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53717521/

相关文章:

ios - Flutter:(iOS)电子邮件地址的文本表单字段自动大写名称

flutter - 在 flutter 中调整容器大小以精确到屏幕大小的一半

c# - GridView:如何设置要显示的行数

Flutter: 'bool' 类型不是 'double' 类型的子类型

android - 状态更改后我的变量重置

Flutter:如何像Google Apps一样用Drawer实现 float SearchBar(Custom AppBar)

flutter - 错误 : Unable to 'pub upgrade' flutter tool. 五秒后重试

flutter - 不同数据类型的 Dart 键值

java - Android-在 GridView 中填充自定义 View

c# - 动态 GridView AllowPaging 在 DataBind 上返回错误