Flutter: Container color overflowing border

Viewed 207

I need to make a container with rounded borders, color, and an outline, but the background color is overflowing the outline color.

How can I fix this?

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
        height: 21,
        constraints: BoxConstraints(
          minWidth: 21,
        ),
        decoration: BoxDecoration(
          border: Border.all(color: Colors.white, width: 2),
          borderRadius: BorderRadius.circular(21),
          color: Colors.pink,
        ),
        child: Align(
            child: Text(
          "1",
          style: TextStyle(
              color: Colors.white, fontWeight: FontWeight.bold, fontSize: 12),
        )));
  }
}

Result: (most visible on the left side)

Pink overflows white border

1 Answers

It... looks like a bug? I think you can report the issue to flutter github.

enter image description here

If you just want a workaround solution, you can try to move the background color (pink) to the lower level of your widget.

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 21,
      constraints: BoxConstraints(
        minWidth: 21,
      ),
      decoration: BoxDecoration(
        border: Border.all(color: Colors.white, width: 2),
        borderRadius: BorderRadius.circular(21),
      ),
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(21),
          color: Colors.pink,
        ),
        child: Align(
          child: Text(
            "1",
            style: TextStyle(
              color: Colors.white, fontWeight: FontWeight.bold, fontSize: 12,
            ),
          ),
        ),
      ),
    );
  }
}
Related