Replies: 2 comments 8 replies
-
Your ideas are great. But some questions might confuse me
|
Beta Was this translation helpful? Give feedback.
-
Hi, I am very glad that the modularization issue is already mentioned here! Thanks @tneotia! Your approach @tneotia is interesting, however there will be a lot of breaking changes plus duplicate package maintenance! I thought about this issue and came up with a different approach: |
Beta Was this translation helpful? Give feedback.
-
This is a discussion on how to tackle the issue of modularization. Some have said to split the package into two with a "_core" version and the full-fat "flutter_html". I had a different sort of idea which I will outline below.
Initial thought process
I was originally thinking about the differences between
customRender
andcustomImageRender
, and if the latter is really necessary now thatcustomRender
will soon have a similar functionality. I think it's great that we provide customization for images, but that bears the question - why don't we do the same for all theReplacedElement
s? We should offer customization for audio, video, etc to allow from asset or memory.That was my starting point. Then I began to think how we could accomplish this without adding a ton of extra parameters like
customAudioRender
,customVideoRender
, and then I realized that the solution I came up with could also serve as a great way to modularize this library. My proposal is as follows:Proposal
Remove
customImageRender
entirely. That's it, really. Users have theRenderContext
exposed to them when making acustomRender
implementation, so they can do the same thing. Sure, it will require a little bit more code (doingcontext.tree.element?.attributes
instead of justattributes
), but it removes a redundancy (at least I think it's a redundancy to havecustomImageRender
).How can this modularize the package?
We remove all the
ReplacedElement
s andLayoutElement
s that use external dependencies (and remove the dependencies too). Then we can create a few different unlisted packages likeflutter_html_audio
andflutter_html_table
. Each of these packages has their own pubspec with dependencies onflutter_html
and whichever dependencies are needed to render their specific tag. Each package exposes oneCustomRender
to the user for that specific tag.We can include a couple
CustomRenderMatcher
s for easy plug-and-play functionality, likevideoMatcher()
oraudioMatcher()
If the user doesn't include these renders, the core package returns an
EmptyContentElement
which eventually will be removed from the tree. If the user does include these renders, then the core package will have all the details to construct the widget.The user can also choose to bypass the unlisted packages and just create their own render with their own dependencies.
An example API is shown below.
Example
There might be holes in this proposal, or you may have a better one. I just wanted to get my idea down into a clear and concise format. Let me know your thoughts!
Beta Was this translation helpful? Give feedback.
All reactions