Skip to content

[Proposal] Modularization #661

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

Merged
merged 16 commits into from
Jan 6, 2022

Conversation

tneotia
Copy link
Contributor

@tneotia tneotia commented May 9, 2021

Here is my PR for modularization, largely based off the written proposal in #645. Includes all changes from #632, but that should be merged first, and a release should be created with those changes.

Fixes #323, fixes #442.

Changes

  • Created packages:
    • flutter_html_all - convenience package that exports all other packages
    • flutter_html_audio - provides audio tag, uses chewie_audio and video_player
    • flutter_html_iframe - provides iframe tag, uses webview_flutter
    • flutter_html_math - provides math tag, uses flutter_math_fork
    • flutter_html_svg - provides svg tag & svg image, uses flutter_svg
    • flutter_html_table - provides table tag, uses flutter_layout_grid
    • flutter_html_video - provides video tag, uses chewie and video_player
  • Core package dependencies reduced to html, csslib, collection 🎉
  • Removed customImageRender and merged with customRender since it basically provides the same effect
  • Removed navigationDelegateForIframe, it can now be set via a parameter in the iframeRender() CustomRender
  • Removed onMathError, it can now be set via a parameter in the mathRender() CustomRender

Pending (complete in order)

  • Change external CustomRenders into functions to keep things consistent with default renders in the "core" library
  • Update docs
  • Check example app for any regressions
  • Publish updated version of flutter_html with customRender changes
  • Change path dependencies to versioned dependencies
  • Publish new packages

Example

Let's say the user wants to have the full-fat flutter_html experience with support for all the tags. With this PR, it would look like this:

pubspec.yaml

flutter_html: ^latest
flutter_html_all: ^latest

.dart

Html(
  data: htmlData,
  customRenders: {
    tableMatcher(): CustomRender.fromWidget(widget: (context, buildChildren) => SingleChildScrollView(
      scrollDirection: Axis.horizontal,
      child: tableRender.widget!.call(context, buildChildren),
    )),
    audioMatcher(): audioRender(),
    iframeMatcher(): iframeRender(/*optionally provide NavigationDelegate here*/),
    mathMatcher(): mathRender(),
    svgTagMatcher(): svgTagRender(),
    svgDataUriMatcher(): svgDataImageRender(),
    svgAssetUriMatcher(): svgAssetImageRender(),
    svgNetworkSourceMatcher(): svgNetworkImageRender(),
    videoMatcher(): videoRender(),
  },
),

Debates

  1. Should we remove customImageRender? I made those changes in a separate commit to make it easily revertable if we decide this. Personally I see no reason for it now, but I could be swayed against this change.
  2. Should we provide a Map<CustomRenderMatcher, CustomRender> in the flutter_html_all package? Rather than the user having to do the above, they could simply do customRenders: allRenders or something like that.

@tneotia
Copy link
Contributor Author

tneotia commented May 12, 2021

@erickok this PR can be reviewed even though 3/6 list items are complete (I can't do the other three, they need to be done after a possible merge of customRender changes and a new release).

This is a proposal after all so if you have different ideas or would like to make your own PR then this can wait.

tneotia added 3 commits May 26, 2021 18:48
…into feature/modularization

� Conflicts:
�	README.md
�	lib/flutter_html.dart
�	lib/html_parser.dart
�	lib/src/replaced_element.dart
…eotia/flutter_html into feature/modularization

� Conflicts:
�	README.md
�	example/lib/main.dart
�	lib/custom_render.dart
�	lib/html_parser.dart
@tneotia
Copy link
Contributor Author

tneotia commented Dec 16, 2021

Seems like this will require quite the merge, I will try to get to this today or tomorrow.

@erickok
Copy link
Contributor

erickok commented Dec 16, 2021

I'm afraid so. It's my fault for having this hang around so long. But we are finally here.

# Conflicts:
#	README.md
#	example/lib/main.dart
#	lib/flutter_html.dart
#	lib/html_parser.dart
#	lib/image_render.dart
#	lib/src/html_elements.dart
#	lib/src/layout_element.dart
#	lib/src/replaced_element.dart
#	lib/src/utils.dart
#	lib/src/widgets/iframe_mobile.dart
#	lib/src/widgets/iframe_unsupported.dart
#	lib/src/widgets/iframe_web.dart
#	pubspec.yaml
#	test/html_parser_test.dart
…into feature/modularization

� Conflicts:
�	lib/flutter_html.dart
�	lib/html_parser.dart
�	lib/src/replaced_element.dart
�	lib/src/utils.dart
@tneotia
Copy link
Contributor Author

tneotia commented Dec 18, 2021

@erickok this is ready to go now. A 3.0.0 migration guide is also created in the wiki.

@erickok
Copy link
Contributor

erickok commented Dec 19, 2021

Thanks so much! I'm going to test tomorrow and merge if all is working.

@tneotia
Copy link
Contributor Author

tneotia commented Dec 19, 2021

Sounds good. Just before merge we would need to create that 3.0.0 alpha release, and update the modularization packages to remove the path dependencies and instead depend on the 3.0.0-alpha flutter_html

@erickok erickok merged commit 86a9bac into Sub6Resources:master Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants