带有3个边框和圆角的容器

3

我正在寻找创建带有左上和右上半径且没有底部边框的圆角容器的方法。以下是我尝试过的方法:

                      Container(
                        decoration: BoxDecoration(
                          border: Border(
                            left: BorderSide(
                              color: AppColors.lightPurple2,
                            ),
                            right: BorderSide(
                              color: AppColors.lightPurple2,
                            ),
                            top: BorderSide(
                              color: AppColors.lightPurple2,
                            ),
                          ),
                          // border: Border.all(
                          //   color: AppColors.lightPurple2,
                          // ),
                          borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(Rad.sm),
                            topRight: Radius.circular(Rad.sm),
                          ),
                        ),

但是这段代码不能正常运行。
======== Exception caught by rendering library =====================================================
The following assertion was thrown during paint():
A borderRadius can only be given for a uniform Border.

The following is not uniform:
BorderSide.color
BorderSide.width
BorderSide.style

然而,如果我使用Border.all(),它可以很好地工作,但我需要以某种方式删除底部边框。如果我删除borderRadius,它会绘制3个边框,但没有圆角。
所以有没有办法同时使用这两个选项?
我最终想要的是: What I want to get eventually

2
这个回答解决了你的问题吗?如何在Flutter中为圆角容器添加有色底部边框? - Ivo
请问您能否添加一个您正在尝试创建的图像吗? - Kaushik Chandru
伊沃,谢谢。但不是真的。我需要一个三面边框,剪辑无法解决。 - Bitlejuce Do
@Kaushik Chandru 当然,已经编辑好了。 - Bitlejuce Do
你正在尝试归档附加的图片吗? - Yeasin Sheikh
是的,那就是我想要的。 - Bitlejuce Do
1个回答

4

你可以使用阴影效果来实现相同的结果

 Container(
                height: 300,
                width: 300,
                decoration: BoxDecoration(
                    borderRadius:
                        BorderRadius.vertical(top: Radius.circular(10)),
                    color: Colors.white,
                    boxShadow: [
                      BoxShadow(
                          color: Colors.purple,
                          offset: Offset(2, -2),
                          spreadRadius: 0,
                          blurRadius: 0),
                      BoxShadow(
                          color: Colors.purple,
                          offset: Offset(-2, -2),
                          spreadRadius: 0,
                          blurRadius: 0)
                    ]))

preview


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接