Size Image widget to parent height but overflow width

I ended finding a very straight forward way to do this using the OverflowBox widget:

new Container(
  child: new OverflowBox(
    minWidth: 0.0, 
    minHeight: 0.0, 
    maxWidth: double.infinity, 
    child: new Image(
      image: new AssetImage('assets/images/bubbles.jpg'), 
      fit: BoxFit.cover)) 
),

When provided double.INFINITY for the maxWidth and no value for maxHeight the OverflowBox sized the image to the height of the container and the width required to display the full image based on the given height.


Give this a try:

new Container(
  decoration: new BoxDecoration(
    image: new DecorationImage(
      image: new AssetImage(
        'assets/images/custom_birthday_card.jpg',
      ),
      fit: BoxFit.cover,
    ),
  ),
);

If you still have a problem after this, check out my card example on GitHub here.

Tags:

Flutter