Repository: flutter
Issue: [vector_graphics] [Suggestion] Automatically convert and create asset class
Labels: package,p: vector_graphics

_Imported from https://github.com/dnfield/vector_graphics/issues/177_

Original report by @ikbendewilliam on Feb 5, 2023

I've played around with the vector graphics and have a suggestion, a simple annotation where you can set all data to convert the svg's into vector files. I've made a working PoC ([fork](https://github.com/ikbendewilliam/vector_graphics/tree/feature/generate-vec-from-svg-using-annotation)) that does the following:

This package provides a tool to generate vector graphics from svg files and creates a dart file with the vector graphics locations.

For example if you have the following structure:

```bash
- assets
  - images
    - subfolder
      - squares.svg
    - flutter.svg
  - different_folder
    - green_rectangle.svg
```

And the following annotation:
```dart 
@VectorGraphics(
  svgSources: [
    VectorGraphicsSource(
      input: 'assets/different_folder/green_rectangle.svg',
    ),
    VectorGraphicsSource(
      inputDir: 'assets/images',
    ),
  ],
)
class VectorGraphicsAssets {}
```

The generator will create .vec files for each svg and create a dart file with the following content:
```dart
class VectorGraphicsAssets {
  static const greenRectangle = 'assets/different_folder/green_rectangle.vec';

  static const squares = 'assets/images/subfolder/squares.vec';

  static const flutter = 'assets/images/flutter.vec';
}
```

I'd love to hear some opinions. The upside is that it is easier to convert, there is automatically a class with all paths and it is updated quite easily. The downside is the use of build_runner, this might not be the best place and the converter command might already be sufficient. 🤔 

---
Comment by @dnfield on Feb 9, 2023
Neat. I haven't though enough about this yet to know if it's really the right path forward but it seems interesting. We've been talking with the flutter_tools team about having some kind of asset transformation available in the build process itself.

/cc @jonahwilliams @andrewkolos FYI

---
Comment by @jonahwilliams on Feb 9, 2023
One big caveat is that we've intentionally avoided specing anything around generating source code. its really unclear what the path forward there would be, at least until we have more information on macros. I suspect that will only come after Dart 3.

---
Comment by @ikbendewilliam on Feb 9, 2023
> One big caveat is that we've intentionally avoided specing anything around generating source code. its really unclear what the path forward there would be, at least until we have more information on macros. I suspect that will only come after Dart 3.

I understand, however this might still take some time as they are indeed working hard on Dart 3. I think I'll have another look and discuss with my colleagues if it's worth releasing a package like this (under my account). It makes it easier to adapt to vector_graphics as you can just add the SVG and a class is generated. But will be obsolete or converted when macro's become available or something similar. 

---
Comment by @dnfield on Feb 9, 2023
If you're interested in maintaining this package I'd be happy to mention it in the readme in this repo.  I'd rather keep it separate for now.

---
Comment by @ikbendewilliam on Feb 10, 2023
That would be perfect, I'll let you know if we decide something 😄 

---
Comment by @ikbendewilliam on Feb 13, 2023
I'm going to check some stuff and make sure that it only generates bin files that it needs to generate etc. Optimise and add some tests. Then I'll publish it and let you know 👍 


---
Comment by @ikbendewilliam on Mar 6, 2023
You can find the repo here: https://github.com/ikbendewilliam/vector_graphics_generator
I'll give you a pub.dev link when I'm ready to publish 😁 

---
Comment by @oravecz-jpmc on Jul 3, 2024
I would rather see a build tool that pulls SVG files from a folder and generates a discrete Icon component for each. The Icon component contains the compiled svg run through the codec and embedded in the icon class.

I don't think the new asset transformation pipeline or macro support will enable this. Perhaps the Mason/Bricks library would with a pre-gen step to identify the relavant SVG files.

The reason why this is important is to enable tree shaking for large icon libraries. If I use one icon from a package containing 1,000 icons, I don't want to pay the file size penalty for all icons.