You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)).
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
The text was updated successfully, but these errors were encountered:
Hey @AlexV525, I've taken a look and also looked in the flutter_gen code. The comment mentioned had the issue that's no longer an issue. In 4bf4cdc, the pubspec.dart JSON data class changed type of assets from List<String> to List<Object>, that you now use to fetch the flavors map specifically for one of flutter_gen features. The same can be done to get transformers field of the particular asset object to get transformers, and if a vector_graphics_compiler exists, pass this to AssetType and use this info in svg_integration.dart to decide whether to use the SvgGenImage or SvgGenImage.vec constructor in the generated file. It looks even more doable than I anticipated at first.
Please reopen, and if you don't have time for the development, I'd be happy to contribute, just tell me.
Sure, I was occupied with business in recent months, so I was unable to produce contributions, but only doing triages and reviews.
The main idea (for me) was to make minimal changes to the core library and try to extend abilities by creating extensions. However, it was unclear how we should make extensions at the moment, so it's been postponed.
Is there an existing issue for this?
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 usingvector_graphics_compiler
package. A few Flutter versions ago, asset transformer support was also added. Andvector_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 theSvgPicture(AssetBytesLoader(path))
.https://pub.dev/packages/flutter_svg#precompiling-and-optimizing-svgs
And
flutter_gen
only gives us thesvg()
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 usesSvgPicture.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 thatSvgPicture
invocation depending on whether it has thevector_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
The text was updated successfully, but these errors were encountered: