FlutterGen / flutter_gen

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.
https://pub.dev/packages/flutter_gen
MIT License
1.44k stars 142 forks source link

[Feature Request] Add support for adding assets from a package #50

Closed jorgecoca closed 3 years ago

jorgecoca commented 3 years ago

Hello! 👋

As a developer, I work on packages that need to contain assets. When that happens, those assets need to be referenced in a different way (see links below):

It'd be amazing for flutter_gen to support this use case.

If you believe this is a valid use case, I'd be more than happy to take a look and come up with a proposal / pull request.

Thank you! 💯

wasabeef commented 3 years ago

I'm also thinking about the best way. If anyone has a good idea, it would be helpful if you could get a pull request.

korzonkiee commented 3 years ago

Hey!

I think a have an idea for a potential solution that might solve that problem.

We could:

  1. Extend FlutterGen with an additional package parameter, so that the user can define it as follows:
    flutter_gen:
    output: lib/generated/
    package: my_ui_package
    lineLength: 80
    integrations:
      flutter_svg: true
  2. Modify _assetGenImageClassDefinition so that it takes package parameter. It would require transforming this constant string value into a parameterized function.
  3. Pass the package parameter to the AssetImage.super(assetName, package) super constructor.

Additionally, SVG integration would need to be updated as follows:

  1. Convert Integration.classOutput getter to method with package argument.
  2. Pass package as a default value for SvgPicture.package field.

Let me know what you think about that solution @wasabeef @jorgecoca

orestesgaolin commented 3 years ago

~I saw that this landed in 3.1.1 but somehow my assets aren't generated with package parameter:~

Edit: I had installed fluttergen both through brew and pub, older version was overtaking the new one. Fixed by removing one from brew.

wasabeef commented 3 years ago

Thanks

om-ha commented 2 years ago

Hey @jorgecoca

As an app developer following this issue's approach, we want to consume the package's assets. Do we have to set every single image asset as an entry in the consumer app's pubspec.yaml file? I hope there's a way to overcome this otherwise it would be too verbose.

See this article -> Example 1: shrine_images -> How an app developer uses the package.