我想建立类似Ios应用store 的设计,如下图所示.

like this

return new Scaffold(
  backgroundColor: Colors.white,
  appBar: buildBar(context),
  // wrap in gesture to dismiss keyboard
  body: new GestureDetector(
    behavior: HitTestBehavior.opaque,
    onPanDown: (detail) {
      FocusScope.of(context).requestFocus(new FocusNode());
    },
    child: new ListView(
      shrinkWrap: true,
      children: <Widget>[
        new Container(
          decoration: new BoxDecoration(color: Colors.grey[400]),
          child: new Column(
            children: <Widget>[
              new SizedBox(height: 15.0),
              new Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  new Icon(Icons.invert_colors,
                      color: Colors.red, size: 45.0),
                  new Text('Top 5',
                      style: new TextStyle(
                          color: Colors.white,
                          fontSize: 25.0,
                          fontWeight: FontWeight.bold)),
                ],
              ),
              new SizedBox(height: 15.0),
            ],
          ),
        ),
        new SizedBox(height: 30.0),
        new ListView.builder(
          shrinkWrap: true,
          itemCount: 5,
          itemBuilder: (BuildContext context, int index) {
            return new Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                new Container(
                  decoration:
                      new BoxDecoration(color: Colors.lightBlue[200]),
                  child: new Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      new Icon(icons[index],
                          size: 30.0),
                      new Padding(
                          padding: const EdgeInsets.only(right: 5.0)),
                      new Text('Category',
                          style: new TextStyle(
                              fontSize: 23.0, fontWeight: FontWeight.bold)),
                    ],
                  ),
                ),
                new SizedBox(height: 5.0),
                new GridView.builder(
                  shrinkWrap: true,
                  scrollDirection: Axis.horizontal,
                  itemCount: 10,
                  gridDelegate:
                      new SliverGridDelegateWithFixedCrossAxisCount(
                          crossAxisCount: 4),
                  itemBuilder: (BuildContext context, int index) {
                    return new GestureDetector(
                        child: new Card(
                          elevation: 5.0,
                          child: new Container(
                            padding: new EdgeInsets.only(
                                bottom: 2.0, right: 3.0),
                            decoration: new BoxDecoration(
                              image: new DecorationImage(
                                fit: BoxFit.cover,
                                image: NetworkImage(
                                    'https://images.unsplash.com/photo-1505535162959-9bbcb4ab22d6?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=0891a99609bf6fdc48842101bef90d67&auto=format&fit=crop&w=500&q=60'),
                              ),
                            ),
                          ),
                        ),
                        onTap: () {
                          print('tapped');
                        });
                  },
                ),
                new SizedBox(height: 20.0),
              ],
            );
          },
        ),
      ],
    ),
  ),
);

但网格视图不会出现,如果我注释掉了网格视图,则显示的列表中没有图像,只有类别名称.

EDIT:

 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),
                ],
              );
            },
          ),
        ),
      ],
    ),
  ),
);

enter image description here

推荐答案

您可以try 在垂直滚动列表中使用水平滚动列表来轻松实现这种类型的布局.

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

shrinkWrap : true

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

EDIT

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

                     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
                          ....
                          ....
                          );

Flutter相关问答推荐

如何在列表磁贴上添加行

当第二页在单独的小工具中使用Navigator.pop时,Navigator.push不起作用

在Flutter中创建具有固定行的压缩水平列表

Flutter 对齐:不适用于多行文字

在Flutter 中每次点击按钮时都很难调用自定义函数

为什么我的页面控制器在使用Riverpod时没有更改我的页面视图?

Flutter 中的 setState() 内部是如何工作的?

Firestore 不会取代 map

如果其他Provider 的帐户已存在,如何阻止用户登录?

如何在Flutter中动态绘制一条从A点到B点的线?

升级到 Flutter 3.10 后,Flutter 键盘填充不起作用. Flutter 3.10 如何防止 BottomSheet 被键盘覆盖?

启动画面中的淡入淡出图像

如何解决需要一个标识符,但得到的是:.try 在:之前插入一个标识符.dart 错误

如何在 Flutter 中的 BackdropFilter.blur 中制作一个 100x100 的清晰孔

如何从 Flutter Slider Widget 中移除发光效果?

在 flutter 中自定义 agora 视频通话 UI

如何在 flutter 中制作这种类型的扩展瓦片

在 Flutter 中将提取的 Listview.builder 与两个列表一起使用

Flutter 中父容器顶部的 Gridview 间距额外区域

阴影效果只出现在一张卡片的左边 在Flutter 中?