[英]How to remove default padding of an Image in Flutter?
As you can see in the screenshot I have some padding in my Images widgets even tho I did not define any.正如您在屏幕截图中看到的那样,即使我没有定义任何内容,我的图像小部件中也有一些填充。 I guess it is the default padding.我猜这是默认填充。 However to cope with my design I'd like to remove this padding.但是,为了应对我的设计,我想删除这个填充。
Here is the code:这是代码:
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))
],
)
],
)
],
),
);
}
}
I already tried to add我已经尝试添加
padding: EdgeInsets.zero,
but that seems not to change anything at all.但这似乎并没有改变任何东西。
I think your issues caused by image, so you should add fit
to image,我认为你的问题是由图像引起的,所以你应该添加fit
图像,
Example:例子:
Image.asset("assets/backpack.jpeg", height: 122, width: 70, fit: BoxFit.fitHeight),
Image.asset("assets/boots.jpeg", height: 122, width: 70, fit: BoxFit.fitHeight),
there are many types of BoxFit, you should consider to choose the right one you need BoxFit有很多种,你应该考虑选择你需要的合适的
try this尝试这个
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: ....,
)
I realized that having a width
to the images kinda added that extra padding.我意识到图像的width
有点增加了额外的填充。 Only having height
(which works fine with constant ratio) did work and removed the padding.只有height
(在恒定比率下工作正常)确实有效并移除了填充。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.