Flutter_svg: SvgPicture does not fill up the container widget

Created on 14 Jan 2021  路  6Comments  路  Source: dnfield/flutter_svg

Container(
    alignment: Alignment.bottomCenter,
    child: SvgPicture.asset(
      img,
      fit: BoxFit.contain,
    ),

Does fit: BoxFit.contain mean the picture would fill up the Container? Seems not working.

All 6 comments

no! it sets the child's size to be as big as possible while still containing the child within the parent's box. It doesn't distort the child's aspect ratio.
ok, if you want the image to fill the container or the parent widget you can use BoxFit.Fill, this will help to fill the image to its parent widget but still there will be some problem with the picture ratio.
thank you

I do want to keep the aspect ratio.

For example, the Container widget is of Size(500, 400). The SvgPicture is rendered as Size(100, 200). What I want is for the image to be rendered as Size(200, 400).

Not sure what I'm doing wrong.

sorry I'm new here I downloaded your code to my computer can you please tell me error path or location where i need to fix. (the path or location of that error)

https://github.com/dnfield/flutter_svg/blob/272f9929f009e0b4e1413095ab4d2e3f3233b8d8/lib/svg.dart#L797-L811

798            width: double.infinity,
799            height: double.infinity,

Seems this solves my issue. Are there APIs for this setting?

Oh I see. :rofl:

ok (:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

joaorpalma picture joaorpalma  路  4Comments

jeffersondarcy picture jeffersondarcy  路  3Comments

au-top picture au-top  路  7Comments

Skyost picture Skyost  路  3Comments

ifiokjr picture ifiokjr  路  5Comments