简体   繁体   中英

How to add spacing between border and container widget

Trying to have space between the border and the container . What I came up with is looking without space something like this

在此处输入图片说明

Code:

Container(
          width: 50,
          decoration: BoxDecoration(
          color: Color(0xFF229592),
          border: Border.all(width: 2, color: Colors.red),
          borderRadius: BorderRadius.circular(25)),
          );

Result expected:

Want the space between the border and container to be in place.

在此处输入图片说明

You can achieve this by creating a Container which has the color white and the border you desired and putting inside this Container another Container with the blue color.

Container(
  width: 50,
  decoration: BoxDecoration(
    color: Colors.white,
    border: Border.all(width: 2, color: Colors.red),
    shape: BoxShape.circle,
  ),
  child: Center(
    child: FractionallySizedBox(
      heightFactor: 0.9, // Adjust those two for the white space
      widthFactor: 0.9,
      child: Container(
        decoration: BoxDecoration(
          color: Color(0xFF229592),
          shape: BoxShape.circle,
        ),
      ),
    ),
  ),
);

The result
在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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