0

I need to design a Container as displayed in the center, below.

enter image description here

Here is my code for doing so:

Container(
   width: 48,
   height: 48,
   decoration: SideBarStyles.recentItem,
   child: Image.network(
     'https://placeimg.com/640/480/any',
     fit: BoxFit.cover,
   ),
),

SideBarStyles.recentItem value

  static BoxDecoration recentItem = BoxDecoration(
    borderRadius: BorderRadius.all(Radius.circular(25)),
    color: Color.fromRGBO(42, 37, 82, 0.15),
    border: Border.all(width: 5, color: Variables.sideBarColorDark)
  );

The problem is image is floating out of the box as:

enter image description here

How do I hide the overflow of the image?

3 Answers 3

1

Heres and example

 Container(
                      width: 48,
                      height: 48,
                      decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        border: Border.all(width: 5, color: Variables.sideBarColorDark),
                        image: new DecorationImage(
                          image: new NetworkImage(
                            'https://placeimg.com/640/480/any',
                          ),
                          fit: BoxFit.cover,
                        ),
                      ),
                    ),
Sign up to request clarification or add additional context in comments.

Comments

1

One way you can do this is like this.

Container(
   width: 48,
   height: 48,
   decoration: SideBarStyles.recentItem,
),

And decoration like this.

  static BoxDecoration recentItem = BoxDecoration(
    borderRadius: BorderRadius.all(Radius.circular(25)),
    color: Color.fromRGBO(42, 37, 82, 0.15),
    border: Border.all(width: 5, color: Variables.sideBarColorDark)
    image: DecorationImage(
      image: NetworkImage('https://placeimg.com/640/480/any'),
    ),
  );

Result:

enter image description here

Comments

0

If you want your container corners to be cropped/rounded either set the borderRadius property in the container to BorderRadius.all(Radius.circular(value)). Or wrap the container in a ClipRRect widget and set the borderRadius property to BorderRadius.all(Radius.circular(value)).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.