Skip to content

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

@janpierry

Description

@janpierry

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

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(),
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: proposalA detailed proposal for a change to Flutterp: flutter_svgThe Flutter SVG drawing packagespackageflutter/packages repository. See also p: labels.team-engineOwned by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions