federico D'Armini
federico D'Armini

Reputation: 311

Make an image bigger respecting original proportions Flutter

If I have an image like this :

Column(
        children: [
          Container(
            child: Image.asset( //this image
              file,
              fit: BoxFit.fill,
            ),
          ),
          _buildContents(),
        ],
      ),

And I want to have this image 1.5x times or 1.2x times bigger (or smaller) without exceeding in width or height, how can I do? (Keeping original proportions safe).

Upvotes: 0

Views: 359

Answers (3)

Islomkhuja Akhrarov
Islomkhuja Akhrarov

Reputation: 1400

You can also use LayoutBuilder widget and depending on the constraint that provides the LayoutBuilder widget specify the size your image

Upvotes: 0

osaxma
osaxma

Reputation: 2974

You should use remove fit: BoxFit.fill since it'll distort the image as per the documentation:

BoxFit.fill: Fill the target box by distorting the source's aspect ratio.

You can safely scale the image using Transform.scale inside the Column such as:

Transform.scale(
  scale: 1.50,
  child: Image.asset(
    file,
  )
),

Upvotes: 2

Manjun Vasudevan
Manjun Vasudevan

Reputation: 286

Please use the scale property of Image.asset()

Upvotes: 0

Related Questions