jovial_svg library

This library offers a 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

ExportedID Core
A record of a node whose id was exported. An ExportedID record gives the bounding rectangle of one instance of the node with the given ID. Multiple bounding rectangles may be created for the same node, e.g. if that node is used multiple times in the SVG from which the ScalableImage was created.
ExportedIDLookup Widget
Used to look up what part of a ScalableImage is clicked on within a ScalableImageWidget.
ScalableImage Core
An image-like asset that can be scaled to any size and rendered without losing resolution, typically derived from an SVG file. 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 Widget
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 Widget
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 Widget
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 Core Widget
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 Core
As of the initial date of publication of this library, there were several bugs in the then-current shipped version of Flutter (2.2.2) involving the dispose() method of ImageDescriptor and ImmutableImageBuffer. The only safe thing to do with this version of Flutter was to refrain from calling dispose() on these objects. This is non-optimal, since it is a potential memory leak. Even if a future version of Flutter correctly uses finalization to eventually dispose of the native memory backing these objects, large amounts of native memory might be retained for a significant amount of time, until the Dart objects are eventually reclaimed and finalized.