svgFromAsset function

Widget svgFromAsset(
  1. String asset, {
  2. Key? key,
  3. Alignment alignment = Alignment.center,
  4. bool excludeFromSemantics = false,
  5. BoxFit fit = BoxFit.contain,
  6. double? height,
  7. String? package,
  8. WidgetBuilder? placeholderBuilder,
  9. String? semanticsLabel,
  10. double? width,
})

Instantiates a widget rendering an SVG picture from an AssetBundle.

The key will be derived from the asset and package arguments. The package argument must be non-null when displaying an SVG from a package and null otherwise.

Either the width and height arguments should be specified, or the widget should be placed in a context that sets tight layout constraints. Otherwise, the image dimensions will change as the image is loaded, which will result in ugly layout changes.

Implementation

Widget svgFromAsset(
  String asset, {
  Key? key,
  Alignment alignment = Alignment.center,
  bool excludeFromSemantics = false,
  BoxFit fit = BoxFit.contain,
  double? height,
  String? package,
  WidgetBuilder? placeholderBuilder,
  String? semanticsLabel,
  double? width,
}) {
  String path = package == null ? asset : 'packages/$package/$asset';
  return _BrowserSvg(
    key: key,
    loader: _AssetSvgLoader(path),
    alignment: alignment,
    excludeFromSemantics: excludeFromSemantics,
    fit: fit,
    height: height,
    placeholderBuilder: placeholderBuilder,
    semanticsLabel: semanticsLabel,
    width: width,
  );
}