From a91239768dea6cb5169ce1c041f0ba9d7d2d23ae Mon Sep 17 00:00:00 2001 From: Stepushchik Denis Date: Fri, 23 Dec 2022 13:19:00 +0300 Subject: [PATCH] Add frame builder, add possibility to smoothly change placeholder to RawPicture --- lib/svg.dart | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/svg.dart b/lib/svg.dart index 43daf847..e86b5150 100644 --- a/lib/svg.dart +++ b/lib/svg.dart @@ -200,6 +200,14 @@ Future precachePicture( return completer.future; } +/// Signature used by [SvgPicture.frameBuilder] to control the widget that will be +/// used when an [SvgPicture] is built. +typedef PictureFrameBuilder = Widget Function( + BuildContext context, + Widget child, + PictureInfo? pictureInfo, +); + /// A widget that will parse SVG data into a [Picture] using a [PictureProvider]. /// /// The picture will be cached using the [PictureCache], incorporating any color @@ -237,6 +245,7 @@ class SvgPicture extends StatefulWidget { this.alignment = Alignment.center, this.matchTextDirection = false, this.allowDrawingOutsideViewBox = false, + this.frameBuilder, this.placeholderBuilder, this.colorFilter, this.semanticsLabel, @@ -337,6 +346,7 @@ class SvgPicture extends StatefulWidget { this.fit = BoxFit.contain, this.alignment = Alignment.center, this.allowDrawingOutsideViewBox = false, + this.frameBuilder, this.placeholderBuilder, Color? color, BlendMode colorBlendMode = BlendMode.srcIn, @@ -401,6 +411,7 @@ class SvgPicture extends StatefulWidget { this.alignment = Alignment.center, this.matchTextDirection = false, this.allowDrawingOutsideViewBox = false, + this.frameBuilder, this.placeholderBuilder, Color? color, BlendMode colorBlendMode = BlendMode.srcIn, @@ -461,6 +472,7 @@ class SvgPicture extends StatefulWidget { this.alignment = Alignment.center, this.matchTextDirection = false, this.allowDrawingOutsideViewBox = false, + this.frameBuilder, this.placeholderBuilder, Color? color, BlendMode colorBlendMode = BlendMode.srcIn, @@ -517,6 +529,7 @@ class SvgPicture extends StatefulWidget { this.alignment = Alignment.center, this.matchTextDirection = false, this.allowDrawingOutsideViewBox = false, + this.frameBuilder, this.placeholderBuilder, Color? color, BlendMode colorBlendMode = BlendMode.srcIn, @@ -573,6 +586,7 @@ class SvgPicture extends StatefulWidget { this.alignment = Alignment.center, this.matchTextDirection = false, this.allowDrawingOutsideViewBox = false, + this.frameBuilder, this.placeholderBuilder, Color? color, BlendMode colorBlendMode = BlendMode.srcIn, @@ -687,6 +701,9 @@ class SvgPicture extends StatefulWidget { /// The [PictureProvider] used to resolve the SVG. final PictureProvider pictureProvider; + /// A builder function responsible for creating the widget that represents this picture. + final PictureFrameBuilder? frameBuilder; + /// The placeholder to use while fetching, decoding, and parsing the SVG data. final WidgetBuilder? placeholderBuilder; @@ -908,6 +925,12 @@ class _SvgPictureState extends State { ? _getDefaultPlaceholder(context, widget.width, widget.height) : widget.placeholderBuilder!(context); } + + final PictureFrameBuilder? frameBuilder = widget.frameBuilder; + if (frameBuilder != null) { + child = frameBuilder.call(context, child, _picture); + } + if (!widget.excludeFromSemantics) { child = Semantics( container: widget.semanticsLabel != null,