Flutter 颤振gridview内部listview

Flutter 颤振gridview内部listview,flutter,Flutter,我想建立类似Ios应用商店的设计,如下图所示。 我试图实现的是有5个顶级类别,每个类别都有显示图像的网格。 我试着这样做 您可以尝试在垂直滚动列表中使用水平滚动列表,以轻松实现此类布局 在水平列表和垂直列表中放置 shrinkWrap : true 或 将列表包装在展开的()小部件中 编辑 这就是我在另一个列表视图中使用列表视图的方式 Container ( child : ListView.buil

我想建立类似Ios应用商店的设计,如下图所示。 我试图实现的是有5个顶级类别,每个类别都有显示图像的网格。 我试着这样做


您可以尝试在垂直滚动列表中使用水平滚动列表,以轻松实现此类布局

在水平列表和垂直列表中放置

shrinkWrap : true

将列表包装在展开的()小部件中

编辑

这就是我在另一个列表视图中使用列表视图的方式

                     Container ( child : 
                        ListView.builder(
                            itemBuilder: (context, subMenuIndex) {
                              return Container(
                                padding: EdgeInsets.only(left: 20.0),
                                child: sideMenuStuff.sideMenuData.elementAt(mainIndex).menu.subMenu.elementAt(subMenuIndex).subSubMenu != null
                                    ? ExpansionTile(
                                  title: Text(sideMenuStuff.sideMenuData.elementAt(mainIndex).menu.subMenu.elementAt(subMenuIndex).zero.info.title,
                                  ),
                                  children: <Widget>[
                                    ListView.builder(
                                        shrinkWrap: true,
                                        itemCount: sideMenuStuff.sideMenuData.elementAt(mainIndex).menu.subMenu.elementAt(subMenuIndex).subSubMenu.length,                                     
                                        itemBuilder:
                                            (context, subSubMenuIndex) {
                                          return Container(
                                            padding: EdgeInsets.only(
                                                left: 40.0,
                                                top: 10.0,
                                                bottom: 10.0),
                                            child:
                                            GestureDetector(
                                              onTap:
                                                  () {
                                                Navigator
                                                    .pop(context);
                                                Navigator
                                                    .of(context)
                                                    .push(MaterialPageRoute(
                                                    builder: (context) =>
                                                        Products(
                                                            sideMenuStuff
                                                                .sideMenuData
                                                                .elementAt(
                                                                mainIndex)
                                                                .menu
                          ....
                          ....
                          );
容器(子:
ListView.builder(
itemBuilder:(上下文,子菜单索引){
返回容器(
填充:仅限边缘设置(左:20.0),
子级:sideMenuStuff.sideMenuData.elementAt(主索引).menu.subMenu.elementAt(子菜单索引).SubSubSubMenu!=null
?扩展文件(
标题:Text(sideMenuStuff.sideMenuData.elementAt(mainIndex).menu.subMenu.elementAt(subMenuIndex).zero.info.title,
),
儿童:[
ListView.builder(
收缩膜:对,
itemCount:sideMenuStuff.sideMenuData.elementAt(主索引).menu.subMenu.elementAt(子菜单索引).SubSubSubMenu.length,
项目生成器:
(上下文,子子菜单索引){
返回容器(
填充:仅限边缘设置(
左:40.0,
排名:10.0,
底部:10.0),
儿童:
手势检测器(
onTap:
() {
领航员
.pop(上下文);
领航员
.of(上下文)
.推动(物料管理器路线)(
生成器:(上下文)=>
产品(
sideMenuStuff
sideMenuData先生
elementAt先生(
主索引)
.菜单
....
....
);

我在
列表视图
中使用了颤振
网格视图
,两者都是垂直滚动的:

body:ListView(
儿童:[
GridView.count(
交叉轴计数:3,
物理:NeverScrollableScrollPhysics(),//禁用GridView的滚动
包覆面提取:true,//您不会看到无限大小错误
儿童:[
容器(
身高:24,
颜色:颜色。绿色,
),
容器(
身高:24,
颜色:颜色,蓝色,
),
],
),
//……其他儿童名单。
],
),
当我使用时,您可以在另一个
列表视图中使用相同的方法进行水平颤振
列表视图
/
网格视图

 GridView.count(
      shrinkWrap: true,
      crossAxisCount: 2,
      physics: ScrollPhysics(),

物理属性,它与我一起工作

物理:ScrollPhysics(),
将在
ListView/GridView
不滚动的情况下起作用,如果父小部件是
SingleChildScrollView
ListView/GridView
为父小部件而不是子小部件提供滚动功能,则可能发生这种情况

解决方案:

 return new Scaffold(
  backgroundColor: Colors.white,
  appBar: new AppBar(
    title: new Text('Search'),
  ),
  body: new GestureDetector(
    behavior: HitTestBehavior.opaque,
    onPanDown: (detail) {
      print(detail);
      FocusScope.of(context).requestFocus(new FocusNode());
    },
    child: new ListView(
      shrinkWrap: true,
      children: <Widget>[
        new SizedBox(height: 20.0),
        new Container(
            height: 60.0,
            color: Colors.blue,
            child: new Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                new Icon(Icons.hourglass_empty,
                    color: Colors.white, size: 30.0),
                new Padding(padding: const EdgeInsets.only(right: 5.0)),
                new Text('TOP5',
                    style:
                        new TextStyle(color: Colors.white, fontSize: 23.0)),
              ],
            ),
          ),
          new SizedBox(height: 20.0),
        new Container(
          child: new ListView.builder(
            shrinkWrap: true,
            itemCount: 5,
            itemBuilder: (context, index) {
              return new Column(
                children: <Widget>[
                  new Container(
                    height: 50.0,
                    color: Colors.green,
                    child: new Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        new Icon(Icons.format_list_numbered,
                            color: Colors.white),
                        new Padding(
                            padding: const EdgeInsets.only(right: 5.0)),
                        new Text(arr[index],
                            style: new TextStyle(
                                fontSize: 20.0, color: Colors.white)),
                      ],
                    ),
                  ),
                  new Container(
                    height: 150.0,
                    child: new ListView.builder(
                      shrinkWrap: true,
                      scrollDirection: Axis.horizontal,
                      itemCount: 10,
                      itemBuilder: (context, index) {
                        return new GestureDetector(
                          child: new Card(
                            elevation: 5.0,
                            child: new Container(
                              height: MediaQuery.of(context).size.width / 3,
                              width: MediaQuery.of(context).size.width / 3,
                              alignment: Alignment.center,
                              child: new Text('Item $index'),
                            ),
                          ),
                          onTap: () {
                            print(123);
                          },
                        );
                      },
                    ),
                  ),
                  new SizedBox(height: 20.0),
                ],
              );
            },
          ),
        ),
      ],
    ),
  ),
);
Scaffold(
      backgroundColor: Colors.white,
      appBar: new AppBar(
        title: new Text('Search'),
      ),
      body: new ListView(
        shrinkWrap: true,
        physics: ScrollPhysics(),
        children: <Widget>[
          new SizedBox(height: 20.0),
          new Container(
            child: new ListView.builder(
              shrinkWrap: true,
              itemCount: 5,
              physics: ScrollPhysics(),
              itemBuilder: (context, index) {
                return new Column(
                  children: <Widget>[
                    new Container(
                      height: 50.0,
                      color: Colors.green,
                      child: new Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          new Icon(Icons.format_list_numbered,
                              color: Colors.white),
                          new Padding(
                              padding: const EdgeInsets.only(right: 5.0)),
                          new Text('List Item',
                              style: new TextStyle(
                                  fontSize: 20.0, color: Colors.white)),
                        ],
                      ),
                    ),
                    new Container(
                      height: 150.0,
                      child: new ListView.builder(
                        shrinkWrap: true,
                        scrollDirection: Axis.horizontal,
                        itemCount: 10,
                        itemBuilder: (context, index) {
                          return new Card(
                            elevation: 5.0,
                            child: new Container(
                              height: MediaQuery.of(context).size.width / 3,
                              width: MediaQuery.of(context).size.width / 3,
                              alignment: Alignment.center,
                              child: new Text('Item $index'),
                            ),
                          );
                        },
                      ),
                    ),
                    new SizedBox(height: 20.0),
                  ],
                );
              },
            ),
          ),
        ],
      ),
    ); 
脚手架(
背景颜色:Colors.white,
appBar:新的appBar(
标题:新文本(“搜索”),
),
正文:新列表视图(
收缩膜:对,
物理:物理(),
儿童:[
新尺寸盒子(高度:20.0),
新容器(
子项:新建ListView.builder(
收缩膜:对,
物品计数:5,
物理:物理(),
itemBuilder:(上下文,索引){
返回新列(
儿童:[
新容器(
身高:50.0,
颜色:颜色。绿色,
孩子:新的一排(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
新图标(Icons.format\u list\u编号,
颜色:颜色。白色),
新填料(
填充:仅限常量边集(右:5.0)),
新文本('列表项',
样式:新文本样式(
fontSize:20.0,颜色:Colors.white),
],
),
),
新容器(
高度:150.0,
子项:新建ListView.builder(
收缩膜:对,
滚动方向:轴水平,
物品计数:10,
itemBuilder:(上下文,索引){
归还新卡(
标高:5.0,
Scaffold(
      backgroundColor: Colors.white,
      appBar: new AppBar(
        title: new Text('Search'),
      ),
      body: new ListView(
        shrinkWrap: true,
        physics: ScrollPhysics(),
        children: <Widget>[
          new SizedBox(height: 20.0),
          new Container(
            child: new ListView.builder(
              shrinkWrap: true,
              itemCount: 5,
              physics: ScrollPhysics(),
              itemBuilder: (context, index) {
                return new Column(
                  children: <Widget>[
                    new Container(
                      height: 50.0,
                      color: Colors.green,
                      child: new Row(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          new Icon(Icons.format_list_numbered,
                              color: Colors.white),
                          new Padding(
                              padding: const EdgeInsets.only(right: 5.0)),
                          new Text('List Item',
                              style: new TextStyle(
                                  fontSize: 20.0, color: Colors.white)),
                        ],
                      ),
                    ),
                    new Container(
                      height: 150.0,
                      child: new ListView.builder(
                        shrinkWrap: true,
                        scrollDirection: Axis.horizontal,
                        itemCount: 10,
                        itemBuilder: (context, index) {
                          return new Card(
                            elevation: 5.0,
                            child: new Container(
                              height: MediaQuery.of(context).size.width / 3,
                              width: MediaQuery.of(context).size.width / 3,
                              alignment: Alignment.center,
                              child: new Text('Item $index'),
                            ),
                          );
                        },
                      ),
                    ),
                    new SizedBox(height: 20.0),
                  ],
                );
              },
            ),
          ),
        ],
      ),
    );