flutter / flutter/flutter

[flutter_svg] Proposal: Add imageBuilder property to SvgPicture for post-load decoration

Open
#182,635 0 comments 0 reactions 0 assignees View on GitHub
c: proposal p: flutter_svg package team-engine
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Use case

Currently, `SvgPicture` provides `placeholderBuilder` and `errorBuilder`, but it lacks a "success" builder equivalent to `imageBuilder` in `CachedNetworkImage`.

If a developer wants to apply a decoration (like a Border, BoxShadow, or BorderRadius) specifically to the resulting image, they must wrap the `SvgPicture` widget in a `Container` or `DecoratedBox`. However, this decoration is then visible even when the image is loading (placeholder) or when it fails (error).

### Proposal

It would be really useful to have a `imageBuilder` property added to `SvgPicture` constructors. This builder should only trigger once the SVG has been successfully parsed and is ready to be painted.

### Proposed API

```dart
SvgPicture.asset(
'assets/icons/logo.svg',
imageBuilder: (BuildContext context, Widget image) {
return Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.blue, width: 2),
borderRadius: BorderRadius.circular(8),
),
child: image,
);
},
placeholderBuilder: (context) => CircularProgressIndicator(),
)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.