Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Automatically convert and create asset class #177

Open
ikbendewilliam opened this issue Feb 5, 2023 · 8 comments
Open

[Suggestion] Automatically convert and create asset class #177

ikbendewilliam opened this issue Feb 5, 2023 · 8 comments

Comments

@ikbendewilliam
Copy link

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) 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:

- assets
  - images
    - subfolder
      - squares.svg
    - flutter.svg
  - different_folder
    - green_rectangle.svg

And the following annotation:

@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:

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. 🤔

@dnfield
Copy link
Owner

dnfield commented 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

@jonahwilliams
Copy link
Collaborator

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.

@ikbendewilliam
Copy link
Author

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.

@dnfield
Copy link
Owner

dnfield commented 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.

@ikbendewilliam
Copy link
Author

That would be perfect, I'll let you know if we decide something 😄

@ikbendewilliam
Copy link
Author

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 👍

@ikbendewilliam
Copy link
Author

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 😁

@oravecz-jpmc
Copy link

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.

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

No branches or pull requests

4 participants