felangel / mason

Tools which allow developers to create and consume reusable templates called bricks.
https://docs.brickhub.dev
963 stars 98 forks source link

feat: Support for hooks in Flutter #509

Closed campovski closed 1 year ago

campovski commented 2 years ago

Description

Currently, using hooks from a Flutter app is not supported due to Isolate.spawnUri invocation.

Requirements

Additional Context

Currently, the only solution to this is to copy paste the logic from hooks into Flutter app. However, this only works if the brick used is always the same (not chosen by the user).

felangel commented 1 year ago

Hi @campovski 👋 Thanks for opening an issue!

Can you please provide a bit more context regarding why you'd want to use mason (and hooks) within a Flutter project? Thanks!

campovski commented 1 year ago

@felangel I am building a desktop app (something in terms of "Flutter project generator") that would take a brick and user-specified values and then generate a skeleton Flutter project with a lot of functionality. Currently, as a workaround, I am doing the hook logic in the app itself, however this is not optimal, because there is code duplication (between hooks and the app code). The purpose of the hook is to create a lot of parameters for the brick, which can be extracted from more general parameters. Simple example would be: I pass in the list of platforms the generated project should support and in hook I add parameters like has_ios, has_android, etc., or even logic such as configuring Firebase App Distribution based on platforms selected and other factors.

Now, I can take the code duplication but what I essentially want to achieve is, that the end user of Flutter project generator would be able to change the underlying brick as well (the brick would still need to take the same parameters though). This is not possible if the hook code is hardcoded in the project generator app itself. The only solution I see that this would work is to extend the number of parameters that brick takes by default to oblivion but even that is not optimal, because if the hook would be used, the author of the brick could in their own hooks generate custom parameters they need and project generator does not provide.

Hope this answered your question. If you want, we can also hop on a call and I can show you the project generator, however it is still closed-source and unfortunately I cannot show it to you publicly.

campovski commented 1 year ago

Another workaround would be to invoke mason CLI with Process.run instead of working with mason from Flutter code. But then again, this would require the user of the app to have mason_cli installed. The FPG could install it automatically but that is not desired.

felangel commented 1 year ago

@campovski sorry for the delayed response. Did you manage to find a solution or would you still be interested in discussing this further?

felangel commented 1 year ago

Closing for now since there hasn't been any activity for a while. Feel free to comment with your thoughts if this is still an issue and I'm happy to continue the conversation 👍