Skip to content

Commit

Permalink
Expose errorBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
amake committed Oct 2, 2024
1 parent 2f7c8ca commit c52c74d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions packages/flutter_svg/lib/svg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ export 'src/cache.dart';
export 'src/default_theme.dart';
export 'src/loaders.dart';

/// The signature that [SvgPicture.errorBuilder] uses to report exceptions.
typedef ErrorWidgetBuilder = Widget Function(
BuildContext context,
Object error,
StackTrace stackTrace,
);

/// Instance for [Svg]'s utility methods, which can produce a [DrawableRoot]
/// or [PictureInfo] from [String] or [Uint8List].
final Svg svg = Svg._();
Expand Down Expand Up @@ -68,6 +75,9 @@ class SvgPicture extends StatelessWidget {
/// A custom `placeholderBuilder` can be specified for cases where decoding or
/// acquiring data may take a noticeably long time, e.g. for a network picture.
///
/// An `errorBuilder` can be specified to provide a custom error display in
/// case the SVG can't be shown.
///
/// The `semanticsLabel` can be used to identify the purpose of this picture for
/// screen reading software.
///
Expand All @@ -82,6 +92,7 @@ class SvgPicture extends StatelessWidget {
this.matchTextDirection = false,
this.allowDrawingOutsideViewBox = false,
this.placeholderBuilder,
this.errorBuilder,
this.colorFilter,
this.semanticsLabel,
this.excludeFromSemantics = false,
Expand Down Expand Up @@ -116,6 +127,9 @@ class SvgPicture extends StatelessWidget {
/// A custom `placeholderBuilder` can be specified for cases where decoding or
/// acquiring data may take a noticeably long time.
///
/// An `errorBuilder` can be specified to provide a custom error display in
/// case the SVG can't be shown.
///
/// The `color` and `colorBlendMode` arguments, if specified, will be used to set a
/// [ColorFilter] on any [Paint]s created for this drawing.
///
Expand Down Expand Up @@ -181,6 +195,7 @@ class SvgPicture extends StatelessWidget {
this.alignment = Alignment.center,
this.allowDrawingOutsideViewBox = false,
this.placeholderBuilder,
this.errorBuilder,
this.semanticsLabel,
this.excludeFromSemantics = false,
this.clipBehavior = Clip.hardEdge,
Expand Down Expand Up @@ -218,6 +233,9 @@ class SvgPicture extends StatelessWidget {
/// A custom `placeholderBuilder` can be specified for cases where decoding or
/// acquiring data may take a noticeably long time, such as high latency scenarios.
///
/// An `errorBuilder` can be specified to provide a custom error display in
/// case the SVG can't be shown.
///
/// The `color` and `colorBlendMode` arguments, if specified, will be used to set a
/// [ColorFilter] on any [Paint]s created for this drawing.
///
Expand All @@ -241,6 +259,7 @@ class SvgPicture extends StatelessWidget {
this.matchTextDirection = false,
this.allowDrawingOutsideViewBox = false,
this.placeholderBuilder,
this.errorBuilder,
ui.ColorFilter? colorFilter,
@deprecated ui.Color? color,
@deprecated ui.BlendMode colorBlendMode = ui.BlendMode.srcIn,
Expand Down Expand Up @@ -279,6 +298,9 @@ class SvgPicture extends StatelessWidget {
/// A custom `placeholderBuilder` can be specified for cases where decoding or
/// acquiring data may take a noticeably long time.
///
/// An `errorBuilder` can be specified to provide a custom error display in
/// case the SVG can't be shown.
///
/// The `color` and `colorBlendMode` arguments, if specified, will be used to set a
/// [ColorFilter] on any [Paint]s created for this drawing.
///
Expand All @@ -299,6 +321,7 @@ class SvgPicture extends StatelessWidget {
this.matchTextDirection = false,
this.allowDrawingOutsideViewBox = false,
this.placeholderBuilder,
this.errorBuilder,
ui.ColorFilter? colorFilter,
@deprecated ui.Color? color,
@deprecated ui.BlendMode colorBlendMode = ui.BlendMode.srcIn,
Expand Down Expand Up @@ -331,6 +354,9 @@ class SvgPicture extends StatelessWidget {
/// A custom `placeholderBuilder` can be specified for cases where decoding or
/// acquiring data may take a noticeably long time.
///
/// An `errorBuilder` can be specified to provide a custom error display in
/// case the SVG can't be shown.
///
/// The `color` and `colorBlendMode` arguments, if specified, will be used to set a
/// [ColorFilter] on any [Paint]s created for this drawing.
///
Expand All @@ -348,6 +374,7 @@ class SvgPicture extends StatelessWidget {
this.matchTextDirection = false,
this.allowDrawingOutsideViewBox = false,
this.placeholderBuilder,
this.errorBuilder,
ui.ColorFilter? colorFilter,
@deprecated ui.Color? color,
@deprecated ui.BlendMode colorBlendMode = ui.BlendMode.srcIn,
Expand Down Expand Up @@ -380,6 +407,9 @@ class SvgPicture extends StatelessWidget {
/// A custom `placeholderBuilder` can be specified for cases where decoding or
/// acquiring data may take a noticeably long time.
///
/// An `errorBuilder` can be specified to provide a custom error display in
/// case the SVG can't be shown.
///
/// The `color` and `colorBlendMode` arguments, if specified, will be used to set a
/// [ColorFilter] on any [Paint]s created for this drawing.
///
Expand All @@ -397,6 +427,7 @@ class SvgPicture extends StatelessWidget {
this.matchTextDirection = false,
this.allowDrawingOutsideViewBox = false,
this.placeholderBuilder,
this.errorBuilder,
ui.ColorFilter? colorFilter,
@deprecated ui.Color? color,
@deprecated ui.BlendMode colorBlendMode = ui.BlendMode.srcIn,
Expand Down Expand Up @@ -460,6 +491,9 @@ class SvgPicture extends StatelessWidget {
/// The placeholder to use while fetching, decoding, and parsing the SVG data.
final WidgetBuilder? placeholderBuilder;

/// The placeholder to use in the event that an error occurs.
final ErrorWidgetBuilder? errorBuilder;

/// If true, will horizontally flip the picture in [TextDirection.rtl] contexts.
final bool matchTextDirection;

Expand Down Expand Up @@ -503,6 +537,7 @@ class SvgPicture extends StatelessWidget {
clipBehavior: clipBehavior,
colorFilter: colorFilter,
placeholderBuilder: placeholderBuilder,
errorBuilder: errorBuilder,
clipViewbox: !allowDrawingOutsideViewBox,
matchTextDirection: matchTextDirection,
);
Expand Down Expand Up @@ -550,6 +585,11 @@ class SvgPicture extends StatelessWidget {
placeholderBuilder,
defaultValue: null,
))
..add(DiagnosticsProperty<Function>(
'errorBuilder',
errorBuilder,
defaultValue: null,
))
..add(DiagnosticsProperty<bool>(
'matchTextDirection',
matchTextDirection,
Expand Down

0 comments on commit c52c74d

Please sign in to comment.