Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter Listview和Gridview的容器高度_Flutter - Fatal编程技术网

Flutter Listview和Gridview的容器高度

Flutter Listview和Gridview的容器高度,flutter,Flutter,Listview和Gridview都需要高度显示在我们的应用程序中。 但每种型号的手机都有不同的大小和高度,因此无法定义列表父容器的静态高度 一旦使用listview和gridview覆盖所有手机型号,我需要为容器设置什么高度 代码: 在这种情况下,高度为500,对于某些手机来说是不错的,但对于其他手机,请告诉我。您可以根据设备使用屏幕高度宽度使其响应: height: MediaQuery.of(context).size.height * 0.1 //It takes 1 of 10 pro

Listview和Gridview都需要
高度
显示在我们的应用程序中。 但每种型号的手机都有不同的大小和高度,因此无法定义列表父容器的静态高度

一旦使用listview和gridview覆盖所有手机型号,我需要为容器设置什么高度

代码:


在这种情况下,高度为500,对于某些手机来说是不错的,但对于其他手机,请告诉我。

您可以根据设备使用屏幕高度宽度使其响应:

height: MediaQuery.of(context).size.height * 0.1 //It takes 1 of 10 proportion of screen height
width: MediaQuery.of(context).size.width* 0.2 //It takes 2 of 10 proportion of screen width

您可以将
GridView
ListView
放在
展开的
小部件中。
扩展的
小部件将占用所有可用空间&您可以轻松显示
网格视图
列表视图
小部件

此解决方案将在多种屏幕尺寸上工作,也不会有任何问题,因为它将自行占用可用空间

Column(
    children: [

    // Any other widget

    Expanded(
        child: GridView.builder(
          itemCount: 20,
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3,
          ),
          itemBuilder: (BuildContext context, int index){
            return GestureDetector(
              onTap: () => showDialog(
                context: context, builder: (context) => AlertDialog(
                  actions: [
                    Image.asset(widget.user.imageUrl),
                    Text(widget.user.name),
                  ],
                ),
              ),
              child: Card(
                elevation: 5,
                child: Image.asset(widget.user.imageUrl),
              ),
            );
          },
        ),
    ),

    // Any other widget

  ],
),

你想在整个屏幕上只显示
listView
还是
gridView
?因为我和bothok有同样的问题,所以我理解你的问题。那么,你在哪里使用这个
listView
gridView
?在一个新的屏幕上,或者在一个有其他窗口小部件的屏幕上?我使用gridview和listview在一个有其他Widgetsys的屏幕上,使用匹配的比例,这只是一个例子
Column(
    children: [

    // Any other widget

    Expanded(
        child: GridView.builder(
          itemCount: 20,
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3,
          ),
          itemBuilder: (BuildContext context, int index){
            return GestureDetector(
              onTap: () => showDialog(
                context: context, builder: (context) => AlertDialog(
                  actions: [
                    Image.asset(widget.user.imageUrl),
                    Text(widget.user.name),
                  ],
                ),
              ),
              child: Card(
                elevation: 5,
                child: Image.asset(widget.user.imageUrl),
              ),
            );
          },
        ),
    ),

    // Any other widget

  ],
),