[flutter_svg] Proposal: Add imageBuilder property to SvgPicture for post-load decoration
- 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
Assessment
This issue has not been assessed yet.