简体   繁体   English

如何创建带有彩色边框 flutter 的装饰圆形容器共享相同的分隔线

[英]How to create decorated rounded container sharing same divider line with colored border flutter

I am trying to replicate the list view below.我正在尝试复制下面的列表视图。 It's a list view(or containers), that you can select, and it will make the border colored and apply a background with no padding between the containers, but there is a thing, they share the same divider line.这是一个列表视图(或容器),您可以使用 select,它会使边框着色并应用容器之间没有填充的背景,但有一点,它们共享相同的分隔线。 I have already given a shot on this, but didn't quite work as I expected.我已经对此进行了尝试,但并没有像我预期的那样工作。 Because the dividers lines got doubled (thicker), and it's kinda annoying.因为分隔线加倍(更厚),这有点烦人。

What I want:我想要的是:

我正在尝试制作的列表视图

EDIT:编辑:

They are selectable containers, so you can click on each one and it will highlight the borders, so if you are thinking of making the middle container one with borders only at the right and left side, it will not work because you will not be able to highlight the top and bottom border.它们是可选择的容器,因此您可以单击每个容器,它会突出显示边框,因此如果您想制作一个仅在右侧和左侧有边框的中间容器,它将无法工作,因为您将无法突出显示顶部和底部边框。

See the example below:请参见下面的示例:

三个容器都可以选择,并且需要共享同一个分隔线

I was trying to make the first container with the bottom border transparent ( bottom: BorderSide(width: 1, color: Colors.transparent), ), so it would not get doubled.我试图使第一个底部边框透明的容器( bottom: BorderSide(width: 1, color: Colors.transparent), ),所以它不会加倍。 But it seems that you can not have a radius container in flutter with different border colors.但似乎您不能在 flutter 中拥有具有不同边框 colors 的半径容器。

What I have made:我做了什么:

我创建的列表视图

Container(
          height: 100,
          width: 200,
          decoration: BoxDecoration(
            color: Colors.blue,
            borderRadius: BorderRadius.only(
              topRight: Radius.circular(20),
              topLeft: Radius.circular(20),
            ),
            border: Border.all(width: 1, color: Colors.red),
          ),
        ),
        Container(
          height: 100,
          width: 200,
          decoration: BoxDecoration(
              border: Border.all(width: 1, color: Colors.black)),
        ),
        Container(
          height: 100,
          width: 200,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.only(
              bottomRight: Radius.circular(20),
              bottomLeft: Radius.circular(20),
            ),
            border: Border.all(width: 1, color: Colors.black),
          ),
        ),

For the middle Container use just border:Border(left:,right:)对于中间Container ,只使用border:Border(left:,right:)


   Container(
            height: 100,
            width: 200,
            decoration: const BoxDecoration(
              border: Border(
                left: BorderSide(
                  color: Colors.green,
                  width: 1,
                ),
                right: BorderSide(
                  color: Colors.green,
                  width: 1,
                ),
              ),
            ),
          ),

try this:尝试这个:

Container(
          height: 100,
          width: 200,
          decoration: BoxDecoration(
            color: Colors.blue,
            borderRadius: BorderRadius.only(
              topRight: Radius.circular(20),
              topLeft: Radius.circular(20),
            ),
            border: isTopSelected ? Border.all(width: 1, color: Colors.red) : 
              Border(
                top: BorderSide(
                  color: Colors.black,
                  width: 1,
                ),
                left: BorderSide(
                  color: Colors.black,
                  width: 1,
                ),
                right: BorderSide(
                  color: Colors.black,
                  width: 1,
                ),
              ),
          ),
        ),
        Container(
          height: 100,
          width: 200,
          decoration: BoxDecoration(
              border: isMiddleSelected ? Border.all(width: 1, color: Colors.red) :
                Border.all(width: 1, color: Colors.Black),
          ),
        ),
        Container(
          height: 100,
          width: 200,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.only(
              bottomRight: Radius.circular(20),
              bottomLeft: Radius.circular(20),
            ),
            border: isBottomSelected ? Border.all(width: 1, color: Colors.red) : 
              Border(
                bottom: BorderSide(
                  color: Colors.black,
                  width: 1,
                ),
                left: BorderSide(
                  color: Colors.black,
                  width: 1,
                ),
                right: BorderSide(
                  color: Colors.black,
                  width: 1,
                ),
              ),
          ),
        ),

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

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