首页 > 解决方案 > RoundedRectangleBorder 不适用于 Container 小部件

问题描述

我需要制作 Container edge circle 以及如何在尝试 RoundedRectangleBorder 时显示错误

 Container(
      width: 100,height: 100,
      margin: EdgeInsets.all(10.0),
      decoration: BoxDecoration(
         color: Colors.orange,
         shape: RoundedRectangleBorder(
            borderRadius: new BorderRadius.circular(18.0),
         )
      ),
 ),

标签: flutterflutter-layout

解决方案


这个错误表明,

参数类型RoundedRectangleBorder不能分配给参数类型BoxShape

所以如果你想使用RoundedRectangleBorder那么你必须在shape参数内部使用它,

Container(
            width: 100,height: 100,
            margin: EdgeInsets.all(10.0),
                    decoration:  ShapeDecoration(
                color: Colors.orange,
              shape: RoundedRectangleBorder( // <--- use this
                borderRadius: BorderRadius.all(
                  Radius.circular(10),
                ),
              ),
            ),
       ),

输出,

在此处输入图像描述

@Anil Chauhan 的方法也是正确的,因此您也可以使用它。


推荐阅读