close

How To stretch an image to fit the whole background 100% height x 100% width in Flutter?

Hello Guys How are you all? Hope You all are fine. I want to know How To stretch an image to fit the whole background 100% height x 100% width in a flutter. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How To stretch an image to fit the whole background 100% height x 100% width in Flutter?

  1. How To stretch an image to fit the whole background 100% height x 100% width in Flutter?

    To stretch an image to fit the whole background 100% height x 100% width in Flutter Container will fit the image to 100% of container width while the height is constant. For local assets, use AssetImage. Just Use Stack's fit property did the trick for my needs. Otherwise Image inside (OctoImageIn my case) was padded and providing other Image.fit values did not give any effect.

  2. stretch an image to fit the whole background 100% height x 100% width in Flutter

    To stretch an image to fit the whole background 100% height x 100% width in Flutter Container will fit the image to 100% of container width while the height is constant. For local assets, use AssetImage. Just Use Stack's fit property did the trick for my needs. Otherwise Image inside (OctoImageIn my case) was padded and providing other Image.fit values did not give any effect.

1. Use Container

Here The following will fit the image to 100% of container width while the height is constant. For local assets, use AssetImage

Container(
  width: MediaQuery.of(context).size.width,
  height: 100,
  decoration: BoxDecoration(
    image: DecorationImage(
      fit: BoxFit.fill,
      image: NetworkImage(yourImage),
    ),
  ),
)

2. Use Stack

Just Use Stack’s fit property did the trick for my needs. Otherwise Image inside (OctoImageIn my case) was padded and providing other Image.fit values did not give any effect.

Stack(
  fit: StackFit.expand, 
  children: [
    Image(
      image: yourImage,
      fit: BoxFit.cover,
    ),
    // other irrelevent children here
  ]
);

3. Use FittedBox

Here To make an Image fill its parent, simply wrap it into a FittedBox:

FittedBox(
  child: Image.asset('foo.png'),
  fit: BoxFit.fill,
)

4. Use Full height and width

For me, works fine the following:

Image(
  image: AssetImage('yourImage'),
  alignment: Alignment.center,
  height: double.infinity,
  width: double.infinity,
  fit: BoxFit.fill,
),

Summery

So, It’s All About this tutorial. I hope this tutorial helps you to Solve your error. Please Comment Below if You stucks anywhere with my code. And please comment below on which solution worked for you. Thank You.

Also Check Out Below Tutorials

Leave a Comment

%d bloggers like this: