简体   繁体   English

如何在 flutter 中为容器添加边框半径?

[英]How to add border radius to a container in flutter?

I'm trying to add border radius to my container but can't get it to work for me.我正在尝试为我的容器添加边框半径,但无法让它为我工作。

Container(
   color: ColorPallete.secondColor[50],
   height: 400.0,
   width: 500.0,
   padding: const EdgeInsets.all(10.0),
   decoration: BoxDecoration(
   borderRadius: BorderRadius.circular(10.0),
   ),
   child: SvgPicture.asset(
     'assets/images/svg/megacategory/art__grocery.svg',
   ),
),

控制台错误

the error that you are receiving is that whenever you have a decoration for a container you need to make sure that color parameter is in the decoration instead of just the container.您收到的错误是,每当您有容器的装饰时,您需要确保颜色参数在装饰中,而不仅仅是容器。 Below I have changed your code to not produce that error message, if you are still having issues getting the border radius to work after this change let me know!下面我已将您的代码更改为不产生该错误消息,如果在此更改后您仍然无法让边界半径工作,请告诉我!

Container(
   height: 400.0,
   width: 500.0,
   padding: const EdgeInsets.all(10.0),
   decoration: BoxDecoration(
       borderRadius: BorderRadius.circular(10.0),
       color: ColorPallete.secondColor[50],
   ),
   child: SvgPicture.asset(
     'assets/images/svg/megacategory/art__grocery.svg',
   ),
),

If you have decoration property in the container, you are supposed to pass the color within the decoration and not the container directly.如果容器中有装饰属性,则应该在装饰中传递颜色,而不是直接传递容器。

Container(
//Not allowed color: ColorPallete.secondColor[50],
height: 400.0,
width: 500.0,
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
color: ColorPallete.secondColor[50], //place it here
borderRadius: BorderRadius.circular(10.0),
),
child: SvgPicture.asset(
 'assets/images/svg/megacategory/art__grocery.svg',
),
),

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

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