Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix this dismissible widget border

Tags:

flutter

dart

I have a problem with a dismissible border which is marked on the screenshot

https://imgur.com/a/Jv0sdi2

return Dismissible(
    child: Container(
        height: 256,
        decoration: ShapeDecoration(
            shape: RoundedRectangleBorder(
                borderRadius: new BorderRadius.circular(20.0)
            )
        )
    );
);
like image 988
kotan37 Avatar asked Aug 18 '19 07:08

kotan37


People also ask

What is Dismissible widget in flutter?

Flutter Widget - Dismissible()Swiping list items left or right to dismiss them is a pretty common UI pattern. To make it work with Flutter, use the Dismissible widget. Dismissible takes a child, a background, and a key, and it will detect swipe gestures and animate the child, sliding over the background.

How do you add a border to a widget in flutter?

Steps to add border to container in Flutter:Step 1: Go to the Container in which you want to add a border. Step 2: Add the decoration parameter and assign the BoxDecoration class. Inside the BoxDecoration add the parameter border and set it to Border. all().


3 Answers

I've encountered the same problem when I was trying to have rounded corners.

Eventually a little workaround did the trick.

Instead of having a background in the Dismissible, create a Stack and put the background widget behind the Dismissible

Stack(
  overflow: Overflow.clip,
  children: <Widget>[
    MyBackgroundWidget(), // instead of background
    Dismissible(
      child: MyForegroundWidget(),
      // no background
    )
  ],
);
like image 84
dumazy Avatar answered Oct 28 '22 08:10

dumazy


The problem is the clipping behavior in dismissible.dart. I've managed to solve the problem by editing the Dismissible class itself. In lines 559 - 573, you will find an if-statement that looks like this:

if (background != null) {
      content = Stack(children: <Widget>[
        if (!_moveAnimation.isDismissed)
          Positioned.fill(
            child: ClipRect(
              clipper: _DismissibleClipper(
                axis: _directionIsXAxis ? Axis.horizontal : Axis.vertical,
                moveAnimation: _moveAnimation,
              ),
              child: background,
            ),
          ),
        content,
      ]);
    }

If you just comment out the clipper-property in ClipRect, the background will be transparent and you won't lose the collapsing animation.

like image 21
NKQDR Avatar answered Oct 28 '22 07:10

NKQDR


I found a solution. Wrap Dismissible widget with ClipRRect widget, and remove borderRadius from, child widgets. Only ClipRRect should have borderRadius.

ClipRRect(
  borderRadius: BorderRadius.circular(15.0),
  child: Dismissible(
    child: YourWidgetContainer();
 )
)

enter image description here

like image 5
SardorbekR Avatar answered Oct 28 '22 07:10

SardorbekR