feat: reduce boilerplate for top-level inherited data #1825
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First of all, I want to thank you for developing this package. It has significantly simplified PDF generation in my Flutter apps and I much prefer using this package over rendering HTML templates to PDF, which I previously did.
However, I’ve encountered a slight usability issue with inherited data. Recently, while working on an invoice PDF, I defined several inherited classes:
I wanted to make all of this data accessible throughout the document’s widget tree, but I found that it required a lot of boilerplate. Currently, each data object must be wrapped in an
InheritedWidget
leading to deeply nested structures like this:And it only gets worse when using
MultiPage
, as every individual widget needs to be wrapped in the same manner.To address this, I’ve introduced a new
inherited
data list for bothPage
andMultiPage
, allowing inherited data to be inserted directly into the page’s base context. This significantly reduces boilerplate:I’d love to hear your thoughts on this approach and any further improvements needed to get this merged.