Reputation:
**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,
),
Upvotes: 4
Views: 7298
Reputation: 1468
Encapsulated in a SizedBox
.
SizedBox(
width: constraints.maxWidth * 0.8,
height: constraints.maxHeight * 0.5,
child: SvgPicture.asset(
AssetsSvgs.illustration1,
fit: BoxFit.cover,
),
)
Upvotes: 0
Reputation: 1828
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
As large as possible while still containing the source entirely within the target box.
As small as possible while still covering the entire target box.
Fill the target box by distorting the source's aspect ratio.
Make sure the full height of the source is shown, regardless of whether this means the source overflows the target box horizontally.
Make sure the full width of the source is shown, regardless of whether this means the source overflows the target box vertically.
Align the source within the target box (by default, centering) and discard any portions of the source that lie outside the box.
As large as possible while still containing the source entirely within the target box.
For more detailed reference see official documentation
Upvotes: 9
Reputation: 61
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'),
),
Upvotes: 1