简体   繁体   English

对于颤振中的圆形属性,形状无法正常工作

[英]Shape is not working properly for circular property in flutter

I'm trying to make a circular image box, but after using shape: Boxshape.circle , it is working properly on my current image.我正在尝试制作一个圆形图像框,但是在使用shape: Boxshape.circle之后,它在我当前的图像上正常工作。 I'm sure that the shape property doesn't depend on the image pixel or any sort of thing.我确信shape属性不依赖于图像像素或任何类型的东西。

I have this code:我有这个代码:

return Column(
    crossAxisAlignment: CrossAxisAlignment.stretch,
    children: <Widget>[
      Container(
        margin: EdgeInsets.only(right: 40.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Container(
              height: 144.0,
              width: 144.0,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                image: DecorationImage(
                  fit: BoxFit.fill,
                  image: AssetImage('MY_IMAGE')
                )
              )
            )
          ]
        )
      )
    ],
);

I have read about the Boxdecoration from this link: Flutter - BoxDecoration .我从这个链接中阅读了关于Boxdecoration的信息: Flutter - BoxDecoration I'm confident that the shape should work but in my case, it is not working.我相信该shape应该可以工作,但就我而言,它不起作用。

This is the result which I'm getting right now:这是我现在得到的结果:

结果图像

Use a ClipRRect inside a SizedBox :ClipRRect内使用SizedBox

  Container(
    child: new SizedBox(
                height: 144.0,
                width: 144.0,
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(72.0),
                  child: new Image.asset('MY_IMAGE'),
                 ),
               ),
             ),

Try this code试试这个代码

Container(
          color: Colors.amber,// this is just for detection, rounded or not
          child: Center(
            child: new Container(
                height: 144.0,
                width: 144.0,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(72),
                    image: DecorationImage(
                        fit: BoxFit.fill,
                        image: AssetImage('assets/img1.png')))),
          ),
        )

Use the same code that you have posted in the question.使用您在问题中发布的相同代码。 But, instead of BoxFit.contain or BoxFit.fill , try using BoxFit.cover .但是,不要使用BoxFit.containBoxFit.fill ,而是尝试使用BoxFit.cover

As it is mentioned in the comment by Mazin Ibrahim in the above answer, the actual height of your image must be less than the radius of the circular container, so even though the container is circular in shape you are not able to see it.正如Mazin Ibrahim在上述答案中的评论中提到的,图像的实际高度必须小于圆形容器的半径,因此即使容器是圆形的,您也无法看到它。

Check this link for more details.查看此链接了解更多详情。

For me it works using ClipOval in the child, and increasing a bit the image size with Transform.scale对我来说,它在孩子中使用 ClipOval 工作,并使用 Transform.scale 增加一点图像大小

                 Container(
                    decoration: BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(40))),
                    child: ClipOval(
                      child: Transform.scale(
                        scale: 1.6,
                        child: Image.asset(
                          "my asset image",
                          width: 80,
                          height: 80,
                          fit: BoxFit.cover,
                        ),
                      ),
                    ),
                  )

For my case it worked like that -就我而言,它是这样工作的 -

 Container(
          height: (20.0),
          width: (20.0),
          decoration: const BoxDecoration(
            shape: BoxShape.circle,
          ),
          child: ClipOval(
            child: SvgPicture.asset(
              'assets/icons/$icon.svg',
              fit: BoxFit.cover,
              color: color,
            ),
          ),
    )

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

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