Skip to content

[FR]: Support flutter_svg asset transformed files (vector_graphics_compiler) #684

Open
@Albert221

Description

@Albert221

Is there an existing issue for this?

  • I have searched the existing issues

Describe the problem

flutter_svg allows us to precompile the SVGs so that the device doesn't have to deal with SVG parsing. This is using vector_graphics_compiler package. A few Flutter versions ago, asset transformer support was also added. And vector_graphics_compiler can work as an asset transformer, which makes the compiled files be made as part of the Flutter app build process (also for flutter run, hot reload etc.) which is very convenient.

But there is one BUT, if we use precompiled vec files instead of normal text SVGs, we can't use SvgPicture.asset, but rather the SvgPicture(AssetBytesLoader(path)).

https://pub.dev/packages/flutter_svg#precompiling-and-optimizing-svgs

And flutter_gen only gives us the svg() method on SVG assets. We can of course make an extension method locally to give that ability, but in bigger codebases (or when we forget/make mistakes) we still have the .svg() available, which will result in a SVG not shown.

Describe the solution

I propose to add a configuration for the flutter_gen in pubspec.yaml to tell the package whether to generate .svg() that uses SvgPicture.asset or the other one. Or even better, more convenient to the user (as we configure asset transformers per asset file/directory and not globally), will look in the pubspec's assets and generate this or that SvgPicture invocation depending on whether it has the vector_graphics_compiler transformer in the YAML for that particular file/directory.

For reference, even the Asset transformation Flutter docs use this vector compiler as the domain example of asset transformation :)

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions