Skip to content

feat: support a custom subclass of SvgGenImage - #790

Open
yonggipo wants to merge 2 commits into
FlutterGen:mainfrom
yonggipo:feat/custom-svg-class
Open

yonggipo wants to merge 2 commits into
FlutterGen:mainfrom
yonggipo:feat/custom-svg-class

Conversation

@yonggipo

Copy link
Copy Markdown

What does this change?

Adds integrations.flutter_svg_class so SVG assets are typed and instantiated with a user-defined subclass of the generated SvgGenImage.

flutter_gen:
  integrations:
    flutter_svg: true
    flutter_svg_class:
      name: AppSvgGenImage
      import: package:my_app/app_svg_gen_image.dart
  • SvgGenImage is still generated so the subclass can extend it
  • asset getters use the custom class as their type and instantiate it (AppSvgGenImage(...) / AppSvgGenImage.vec(...))
  • the configured import is added to the generated file
  • without the option, the output is unchanged (no existing actual_data file changed)

This PR is stacked on #788 (errorBuilder for svg()), because both touch the same lines of SvgIntegration. The new change is the last commit, feat: support a custom subclass of SvgGenImage. I'll rebase once #788 is merged or closed.

Fixes #789 🎯

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • Make sure to open a GitHub issue as a bug/feature request before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
    • Ensure the tests (melos run test)
    • Ensure the analyzer and formatter pass (melos run format to automatically apply formatting)
  • Appropriate docs were updated (if necessary)

Added test_resources/pubspec_assets_svg_custom_class.yaml with its generated actual_data, a unit test for the custom class name, constructors and import, and a README section. Regenerated pubspec.g.dart with build_runner.

🤖 Generated with Claude Code

yonggipo and others added 2 commits October 17, 2026 13:54
SvgPicture.errorBuilder is available since flutter_svg 2.0.17,
so the parameter is generated only when the resolved flutter_svg
version (or version constraint) allows 2.0.17 or later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add `integrations.flutter_svg_class` (name and import) so SVG assets
are typed and instantiated with a user-defined subclass of the
generated `SvgGenImage`. This lets projects override `svg()` and add
their own methods while keeping the generated base class.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR]: Allow a custom subclass of the generated SvgGenImage

1 participant