Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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 颤振-如何使水平列表视图中的每个图像适合屏幕?_Flutter - Fatal编程技术网

Flutter 颤振-如何使水平列表视图中的每个图像适合屏幕?

Flutter 颤振-如何使水平列表视图中的每个图像适合屏幕?,flutter,Flutter,我创建了一个水平的ListView,它包含很多图像,但是ListView中的每个图像都不适合屏幕(有时我必须滚动才能看到它的其余部分,当然还有下一个图像的一部分)。如何拉伸每个图像以适应屏幕并滚动查看下一个图像 (下一张图片也必须适合屏幕) 更新示例 您可以将DecorationImage与BoxFit.fill一起使用 例如: Container( width: 64.0, height: 64.0, decoration: new

我创建了一个水平的ListView,它包含很多图像,但是ListView中的每个图像都不适合屏幕(有时我必须滚动才能看到它的其余部分,当然还有下一个图像的一部分)。如何拉伸每个图像以适应屏幕并滚动查看下一个图像 (下一张图片也必须适合屏幕)

更新示例

您可以将
DecorationImage
BoxFit.fill一起使用

例如:

Container(
          width: 64.0,
          height: 64.0,
          decoration: new BoxDecoration(
            shape: BoxShape.circle,
            image: new DecorationImage(
                fit: BoxFit.fill,
                image: new NetworkImage('my_url.jpg')
            )
        )) 

您可以将此代码用于具有完美拟合图像的水平列表视图

 Container(
            height: 275,
            child: ListView.builder(
              scrollDirection: Axis.horizontal,
              shrinkWrap: true,
              itemCount: furnitures.length,
              itemBuilder: (BuildContext context, int index) {
                Map furniture = furnitures[index];

                return Padding(
                  padding: EdgeInsets.only(right: 20),
                  child: GestureDetector(
                    onTap: (){
                      Navigator.of(context).push(
                        MaterialPageRoute(
                          builder: (BuildContext context){
                            return Details();
                          },
                        ),
                      );
                    },
                    child: Container(
                      height: 275,
                      width: 280,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          Text(
                            furniture['name'],
                            style: TextStyle(
                              fontWeight: FontWeight.bold,
                              fontSize: 20,
                            ),
                          ),
                          SizedBox(height: 10),
                          ClipRRect(
                            borderRadius: BorderRadius.circular(15),
                            child: Image.asset(
                              "${furniture["img"]}",
                              height: 240,
                              width: 280,
                              fit: BoxFit.cover,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                );
              },

            ),
          )
容器(
身高:275,
子项:ListView.builder(
滚动方向:轴水平,
收缩膜:对,
物品数量:家具。长度,
itemBuilder:(构建上下文,int索引){
地图家具=家具[索引];
返回填充(
填充:仅限边缘设置(右:20),
儿童:手势检测器(
onTap:(){
导航器.of(上下文).push(
材料路线(
生成器:(BuildContext上下文){
返回详细信息();
},
),
);
},
子:容器(
身高:275,
宽度:280,
子:列(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
正文(
家具[“名称”],
样式:TextStyle(
fontWeight:fontWeight.bold,
尺寸:20,
),
),
尺寸箱(高度:10),
ClipRRect(
边界半径:边界半径。圆形(15),
子:Image.asset(
“${家具[“img”]}”,
身高:240,
宽度:280,
适合:BoxFit.cover,
),
),
],
),
),
),
);
},
),
)

您可以使用来实现这一点。只需键入
MediaQuery.of(context).size.width
即可获得设备屏幕的宽度,然后将图像的宽度指定给该窗口

我指的是carousel小部件,以前从未听说过。我是移动开发的新手。

不,我的意思是将水平列表视图中的每个图像拉伸到屏幕上,而不仅仅是单个图像。你可以有一个模型或屏幕截图。我不知道你是什么意思?更新了示例,所以我认为你可以将图像的宽度设置为与屏幕大小相等。获取屏幕大小的宽度。您可以使用“``MediaQuery.of(context).size.width```