jovial_svg library

This library offers a static ScalableImage that can be loaded from:

  • An SVG file.
  • An Android Vector Drawable file
  • A more compact and much more efficient .si file that was compiled from an SVG or AVD file.

A robust profile of SVG targeted at static images is supported. It generally consists of the features that are relevant to static images defined in SVG Tiny 1.2, plus many commonly-used elements from SVG 1.1. More details about the supported SVG profile can be found in the top-level documentation, or in the github repo's README.

A compact .si file can be created with dart run jovial_svg:svg_to_si or dart run jovial_svg:avd_to_si (after running dart pub get).

ScalableImageWidget can be used to display a ScalableImage. The image can be automatically scaled by the widget, and fit into the available area with a BoxFit and an Alignment. ScalableImageWidget will, if needed, asynchronously load a ScalableImage asset and prepare any embedded pixel-based images.

Classes

ScalableImage
The main entry point to this library. This class features several static methods to load a ScalableImage from various sources. It provides two in-memory representations: a memory-saving "compact" representation, as well as a faster internal graph structure. Provision is given to set a viewport, and prune away nodes that are outside this viewport. In this way, several smaller "views" onto a larger SI asset can be produced, with maximal resource sharing between the different assets.
ScalableImageCache
An LRU cache of ScalableImage futures derived from ScalableImageSource instances. A cache with a non-zero size could make sense, for example, as part of the state of a stateful widget that builds entries on demand, and that uses ScalableImageWidget.fromSISource to asynchronously load scalable images. See, for example, cache.dart in the example directory.
ScalableImageSource
An asynchronous source of a ScalableImage. This is used for asynchronous loading of an SI asset by a ScalableImageWidget, e.g from an AssetBundle. This class may be subclassed by clients of this library, e.g. for loading from other network sources.
ScalableImageWidget
A widget for displaying a ScalableImage. The image can be automatically scaled by the widget, and fit into the available area with a BoxFit and an Alignment.
ScalingTransform
A coordinate system transformation to fit a ScalableImage into a given container, for a given BoxFit and Alignment. This class is offered as a convenience for scaling ScalableImage instances. It also helps converting positions as rendered back into the ScalableImage's coordinate, e.g. when mapping a touch event into the original SVG's coordinate space.

Enums

ImageDisposeBugWorkaround
In Flutter version 3.10.4 (June 2023), an inconfirmed report of a new Flutter bug related to dispose() and image handling was reported -- see https://github.com/zathras/jovial_svg/issues/62. silentlyIgnoreErrors was added at this time.