0

There are several posts, like this one, describing how to add rounded corners to an images using ClipRRect. They're working for me except my images aren't constraining properly in width. E.g., my attempt at a square image below

ListView(                       // <- Works fine when not in ListView?
 children: <Widget>[
Padding(
  padding: const EdgeInsets.all(8.0),
  child: GestureDetector(
    onTap: () => _getFromGallery(),
    child: Container(
      color: Colors.blue,
      child: ClipRRect(
        borderRadius: BorderRadius.circular(50.0), //or 15.0
        child: CachedNetworkImage(
          imageUrl: image,
          height: 150.0,
          width: 150.0,
          fit: BoxFit.cover,
        ),
      ),
    ),
  ),
),
]

has the proper height but the width expands the whole device screen, like this?

enter image description here

EDIT

This attempt

return Container(
    height: 150.0,
    width: 150.0,
    color: Colors.blue,
    child: ClipRRect(
      borderRadius: BorderRadius.circular(50.0), //or 15.0
      child: CachedNetworkImage(
        imageUrl: image,
        height: 150.0,
        width: 150.0,
        fit: BoxFit.fill,
      ),
    ),
  );

Created this

Edit

EDIT #2

Image with no ListView

enter image description here

buttonsrtoys
  • 2,359
  • 3
  • 32
  • 52

1 Answers1

2

From the description of ListView, "In the cross axis, the children are required to fill the ListView." So, ListView was expanding my container? Either way, wrapping Padding in a Center widget fixed it.

buttonsrtoys
  • 2,359
  • 3
  • 32
  • 52