Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to stretching SVG in flutter?

**How can i stretch svg image ?

the code is:**

child: SvgPicture.asset(   
                  'assets/images/accessories.svg',
                  height: constraints.maxHeight * 0.5,
                  width: constraints.maxWidth * 0.8,
                ),

2 Answers

You can use the fit property for SvgPicture widget to provide the fitting on the asset image according to need. Some of the properties for fit are

BoxFit.contain

As large as possible while still containing the source entirely within the target box.

BoxFit.cover

As small as possible while still covering the entire target box.

BoxFit.fill

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

BoxFit.fitHeight

Make sure the full height of the source is shown, regardless of whether this means the source overflows the target box horizontally.

BoxFit.fitWidth

Make sure the full width of the source is shown, regardless of whether this means the source overflows the target box vertically.

BoxFit.none

Align the source within the target box (by default, centering) and discard any portions of the source that lie outside the box.

BoxFit.scaleDown

As large as possible while still containing the source entirely within the target box.

For more detailed reference see official documentation

like image 77
harpreet seera Avatar answered Nov 10 '25 00:11

harpreet seera


You can use the fit property for the SvgPicture widget this way below.

Widget build(BuildContext context) {
    return Container(
      child: Stack(
        children: [
          FittedBox(
            fit: BoxFit.cover,
            child: SvgPicture.asset('assets/icons/bg.svg'),
          ),


like image 38
Salami Tobi Avatar answered Nov 09 '25 23:11

Salami Tobi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!