繁体   English   中英

如何在 Flutter 中删除图像的默认填充?

[英]How to remove default padding of an Image in Flutter?

正如您在屏幕截图中看到的那样,即使我没有定义任何内容,我的图像小部件中也有一些填充。 我猜这是默认填充。 但是,为了应对我的设计,我想删除这个填充。

这是代码:

class PackingPlanEntry extends StatelessWidget {
  const PackingPlanEntry({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
          color: Color.fromRGBO(208, 190, 162, 100.0),
          shape: BoxShape.rectangle,
          borderRadius: BorderRadius.all(Radius.circular(5))),
      child: Row(
        children: [
          Image.asset("assets/backpack.jpeg", height: 122, width: 70),
          Image.asset("assets/boots.jpeg", height: 122, width: 70),
          Column(
            children: [
              Text(
                "Norwegen Tour 2022",
                style: TextStyle(
                    color: Colors.black,
                    fontSize: 16,
                    fontFamily: "Roboto",
                    fontWeight: FontWeight.bold),
              ),
              Row(
                children: [
                  Text(
                    "12 Teile gepackt",
                    style: TextStyle(
                        color: Color.fromARGB(400, 0, 0, 0),
                        fontSize: 12),
                  ),
                  Text("3",
                      style: TextStyle(
                          color: Colors.black.withOpacity(0.5))),
                  Image.asset("assets/user.png",
                      color: Colors.black.withOpacity(0.5))
                ],
              )
            ],
          )
        ],
      ),
    );
  }
}

我已经尝试添加

      padding: EdgeInsets.zero,

但这似乎并没有改变任何东西。

在此处输入图像描述

我认为你的问题是由图像引起的,所以你应该添加fit图像,

例子:

Image.asset("assets/backpack.jpeg", height: 122, width: 70, fit: BoxFit.fitHeight),
Image.asset("assets/boots.jpeg", height: 122, width: 70, fit: BoxFit.fitHeight),

BoxFit有很多种,你应该考虑选择你需要的合适的

尝试这个

Container(
            padding: EdgeInsets.zero,
              decoration: const BoxDecoration(
              color: Color.fromRGBO(208, 190, 162, 100.0),
              shape: BoxShape.rectangle,
              borderRadius: BorderRadius.all(Radius.circular(5))),
              child: ....,
            )

我意识到图像的width有点增加了额外的填充。 只有height (在恒定比率下工作正常)确实有效并移除了填充。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM