Assume I have a simple function that takes a URL to an svg image and returns a widget:
Widget loadImage(String url, { height, width }) {
// Wrap URL in an SvgPicture and return
return SvgPicture.network(url)
}
I'd like to apply the width
and height
params to SvgPicture
only if they are defined. Something like this (though this obviously results in a syntax error):
Widget loadImage(String url, { height, width }) {
// Wrap URL in an SvgPicture and return
return SvgPicture.network(
url,
if(height) height : height, // <--
if(width) width : width, // <--
)
}
How do I do this?