diff --git a/.circleci/config.yml b/.circleci/config.yml index 010547222b..718328b1f8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,4 +37,4 @@ jobs: command: melos run analyze - run: name: Check That Flutter Code is Formatted Correctly - command: flutter format -o none --set-exit-if-changed . + command: dart format -o none --set-exit-if-changed . diff --git a/.github/flutter_html_screenshot.png b/.github/flutter_html_screenshot.png deleted file mode 100644 index 3d1b893b61..0000000000 Binary files a/.github/flutter_html_screenshot.png and /dev/null differ diff --git a/.github/flutter_html_screenshot2.png b/.github/flutter_html_screenshot2.png deleted file mode 100644 index eb47b0e146..0000000000 Binary files a/.github/flutter_html_screenshot2.png and /dev/null differ diff --git a/.github/flutter_html_screenshot3.png b/.github/flutter_html_screenshot3.png deleted file mode 100644 index 75a065879d..0000000000 Binary files a/.github/flutter_html_screenshot3.png and /dev/null differ diff --git a/.gitignore b/.gitignore index caf0d56dbf..188d2e1fa5 100644 --- a/.gitignore +++ b/.gitignore @@ -154,4 +154,6 @@ modules.xml packages/**/pubspec_overrides.yaml ./pubspec_overrides.yaml -/example/pubspec_overrides.yaml \ No newline at end of file +/example/pubspec_overrides.yaml + +coverage/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 122bb26fbb..80c8b6f22a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +# Change Log + + +#### 3.0.0-beta.1 - *May 2023* + + - Several Breaking Changes. See the [migration guide](https://github.com/Sub6Resources/flutter_html/wiki/Migration-Guides#300) + + - **FIX**: Aspect ratio exception when height is 0 ([#1222](https://github.com/sub6resources/flutter_html/issues/1222)). ([ed75f8fe](https://github.com/sub6resources/flutter_html/commit/ed75f8fef779e920ecc1f27719a4150a29e3ebee)) + - **FIX**: Fix issue with font scaling introduced in 3.0.0-alpha.6 ([#1173](https://github.com/sub6resources/flutter_html/issues/1173)). ([c75e0dfb](https://github.com/sub6resources/flutter_html/commit/c75e0dfb1be6cb79748f719487043d12bc330c60)) + - **FIX**: Fix various issues with list rendering. ([520ff3c3](https://github.com/sub6resources/flutter_html/commit/520ff3c326d5dc8f5a601022c2a32d58e2e83cbb)) + - **FIX**: Apply margins to
Screenshot 1 | -Screenshot 2 | -Screenshot 3 | -
- | - | - |
flutter_html supports a variety of HTML and CSS tags and attributes.
+Over a hundred static tags are supported out of the box.
+Or you can even define your own using an Extension
:
Its easy to add custom styles to your Html as well using the Style
class:
Here's a fancy <p> element!
+ """, + extensions: [ + TagExtension( + tagsToExtend: {"flutter"}, + child: const FlutterLogo(), + ), + ], + style: { + "p.fancy": Style( + textAlign: TextAlign.center, + padding: const EdgeInsets.all(16), + backgroundColor: Colors.grey, + margin: Margins(left: Margin(50, Unit.px), right: Margin.auto()), + width: Width(300, Unit.px), + fontWeight: FontWeight.bold, + ), + }, + ); +} +``` -## Table of Contents: +becomes... -- [Installing](#installing) + -- [Currently Supported HTML Tags](#currently-supported-html-tags) +## Table of Contents: -- [Currently Supported CSS Attributes](#currently-supported-css-attributes) +- [Supported HTML Tags](https://github.com/Sub6Resources/flutter_html/wiki/Supported-HTML-Elements) -- [Currently Supported Inline CSS Attributes](#currently-supported-inline-css-attributes) +- [Supported CSS Attributes](https://github.com/Sub6Resources/flutter_html/wiki/Supported-CSS-Attributes) - [Why flutter_html?](#why-this-package) +- [Migration Guide](#migration-guides) + - [API Reference](#api-reference) - [Constructors](#constructors) - - [Selectable Text](#selectable-text) - - [Parameters Table](#parameters) - - [Methods](#methods) - - - [Getters](#getters) - - - [Data](#data) - - - [Document](#document) - - - [onLinkTap](#onlinktap) - - - [customRender](#customrender) - - - [onImageError](#onimageerror) - - - [onImageTap](#onimagetap) - - - [tagsList](#tagslist) - - - [style](#style) - -- [Rendering Reference](#rendering-reference) - - - [Image](#image) - - [External Packages](#external-packages) - [`flutter_html_all`](#flutter_html_all) @@ -79,56 +73,21 @@ A Flutter widget for rendering HTML and CSS as Flutter widgets. - [`flutter_html_video`](#flutter_html_video) -- [Notes](#notes) - -- [Migration Guide](#migration-guides) - -- [Contribution Guide](#contribution-guide) - -## Installing: - -Add the following to your `pubspec.yaml` file: +- [Frequently Asked Questions](#faq) - dependencies: - flutter_html: ^3.0.0-alpha.5 - // Or flutter_html_all: ^3.0.0-alpha.5 to include table, video, audio, iframe... +- [Example](#example) -## Currently Supported HTML Tags: -| | | | | | | | | | | | -|------------|-----------|-------|-------------|---------|---------|-------|------|--------|--------|--------| -|`a` | `abbr` | `acronym`| `address` | `article`| `aside` | `audio`| `b` | `bdi` | `bdo` | `big` | -|`blockquote`| `body` | `br` | `caption` | `cite` | `code` | `data`| `dd` | `del` | `details` | `dfn` | -| `div` | `dl` | `dt` | `em` | `figcaption`| `figure`| `footer`| `font` | `h1` | `h2` | `h3` | -| `h4` | `h5` |`h6` | `header` | `hr` | `i` | `iframe`| `img` | `ins` | `kbd`| `li` | -| `main` | `mark` | `nav` | `noscript`|`ol` | `p` | `pre` | `q` | `rp` | `rt` | `ruby` | -| `s` | `samp` | `section` | `small` | `span`| `strike` | `strong`| `sub` | `sup` | `summary` | `svg`| -| `table` | `tbody` | `td` | `template` | `tfoot` | `th` | `thead` |`time` | `tr` | `tt` | `u` | -| `ul` | `var` | `video` | `math`: | `mrow` | `msup` | `msub` | `mover` | `munder` | `msubsup` | `moverunder` | -| `mfrac` | `mlongdiv` | `msqrt` | `mroot` | `mi` | `mn` | `mo` | | | | | - - -## Currently Supported CSS Attributes: -| | | | | | | | -|------------------|--------|------------|----------|--------------|------------------------|------------| -|`background-color`| `color`| `direction`| `display`| `font-family`| `font-feature-settings`| `font-size`| -|`font-style` | `font-weight`| `height` | `letter-spacing`| `line-height`| `list-style-type` | `list-style-position`| -|`padding` | `margin`| `text-align`| `text-decoration`| `text-decoration-color`| `text-decoration-style`| `text-decoration-thickness`| -|`text-shadow` | `vertical-align`| `white-space`| `width` | `word-spacing`| | | - -## Currently Supported Inline CSS Attributes: -| | | | | | | | -|------------------|--------|------------|----------|--------------|------------------------|------------| -|`background-color`| `border` (including specific directions) | `color`| `direction`| `display`| `font-family`| `font-feature-settings` | -| `font-size`|`font-style` | `font-weight`| `line-height` | `list-style-type` | `list-style-position`|`padding` (including specific directions) | -| `margin` (including specific directions) | `text-align`| `text-decoration`| `text-decoration-color`| `text-decoration-style`| `text-shadow` | | - -Don't see a tag or attribute you need? File a feature request or contribute to the project! ## Why this package? This package is designed with simplicity in mind. Originally created to allow basic rendering of HTML content into the Flutter widget tree, this project has expanded to include support for basic styling as well! -If you need something more robust and customizable, the package also provides a number of optional custom APIs for extremely granular control over widget rendering! + +If you need something more robust and customizable, the package also provides a number of extension APIs for extremely granular control over widget rendering! + +## Migration Guides + +[3.0.0 Migration Guide](https://github.com/Sub6Resources/flutter_html/wiki/Migration-Guides#300) ## API Reference: @@ -146,418 +105,30 @@ The `Html()` constructor is for those who would like to directly pass HTML from If you would like to modify or sanitize the HTML before rendering it, then `Html.fromDom()` is for you - you can convert the HTML string to a `Document` and use its methods to modify the HTML as you wish. Then, you can directly pass the modified `Document` to the package. This eliminates the need to parse the modified `Document` back to a string, pass to `Html()`, and convert back to a `Document`, thus cutting down on load times. -#### Selectable Text - -The package also has two constructors for selectable text support - `SelectableHtml()` and `SelectableHtml.fromDom()`. - -The difference between the two is the same as noted above. - -Please note: Due to Flutter [#38474](https://github.com/flutter/flutter/issues/38474), selectable text support is significantly watered down compared to the standard non-selectable version of the widget. The changes are as follows: - -1. The list of tags that can be rendered is significantly reduced. Key omissions include no support for images/video/audio, table, and ul/ol. - -2. No support for `customRender`, `customImageRender`, `onImageError`, `onImageTap`, `onMathError`, and `navigationDelegateForIframe`. (Support for `customRender` may be added in the future). - -3. Styling support is significantly reduced. Only text-related styling works (e.g. bold or italic), while container related styling (e.g. borders or padding/margin) do not work. - -Once the above issue is resolved, the aforementioned compromises will go away. Currently the `SelectableText.rich()` constructor does not support `WidgetSpan`s, resulting in the feature losses above. - ### Parameters: -| Parameters | Description | -|--------------|-----------------| -| `data` | The HTML data passed to the `Html` widget. This is required and cannot be null when using `Html()`. | -| `document` | The DOM document passed to the `Html` widget. This is required and cannot be null when using `Html.fromDom()`. | -| `onLinkTap` | A function that defines what the widget should do when a link is tapped. The function exposes the `src` of the link as a `String` to use in your implementation. | -| `customRenders` | A powerful API that allows you to customize everything when rendering a specific HTML tag. | -| `onImageError` | A function that defines what the widget should do when an image fails to load. The function exposes the exception `Object` and `StackTrace` to use in your implementation. | -| `shrinkWrap` | A `bool` used while rendering different widgets to specify whether they should be shrink-wrapped or not, like `ContainerSpan` | -| `onImageTap` | A function that defines what the widget should do when an image is tapped. The function exposes the `src` of the image as a `String` to use in your implementation. | -| `tagsList` | A list of elements the `Html` widget should render. The list should contain the tags of the HTML elements you wish to include. | -| `style` | A powerful API that allows you to customize the style that should be used when rendering a specific HTMl tag. | -| `selectionControls` | A custom text selection controls that allow you to override default toolbar and build toolbar with custom text selection options. See an [example](https://github.com/justinmc/flutter-text-selection-menu-examples/blob/master/lib/custom_menu_page.dart). | - -### Methods: - -| Methods | Description | -|--------------|-----------------| -| `disposeAll()` | Disposes all `ChewieController`s, `ChewieAudioController`s, and `VideoPlayerController`s being used by every `Html` widget. (Note: `Html` widgets automatically dispose their controllers, this method is only provided in case you need other behavior) | - -### Getters: - -1. `Html.tags`. This provides a list of all the tags the package renders. The main use case is to assist in excluding elements using `tagsList`. See an [example](#example-usage---tagslist---excluding-tags) below. +| Parameters | Description | +|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `data` | The HTML data passed to the `Html` widget. This is required and cannot be null when using `Html()`. | +| `document` | The DOM document passed to the `Html` widget. This is required and cannot be null when using `Html.fromDom()`. | +| `onLinkTap` | Optional. A function that defines what the widget should do when a link is tapped. The function exposes the `src` of the link as a `String` to use in your implementation. | +| `extensions` | Optional. A powerful API that allows you to customize everything when rendering a specific HTML tag. | +| `shrinkWrap` | Optional. A `bool` used while rendering different widgets to specify whether they should be shrink-wrapped or not, like `ContainerSpan` | +| `onlyRenderTheseTags` | Optional. An exclusive set of elements the `Html` widget should render. Note that your html will be wrapped in `` and `` if it isn't already, so you should include those in this list. | +| `doNotRenderTheseTags` | Optional. A set of tags that should not be rendered by the `Html` widget. | +| `style` | Optional. A powerful API that allows you to customize the style that should be used when rendering a specific HTMl tag. | -2. `SelectableHtml.tags`. This provides a list of all the tags that can be rendered in selectable mode. -3. `Html.chewieAudioControllers`. This provides a list of all `ChewieAudioController`s being used by `Html` widgets. +More examples and in-depth details are available: -4. `Html.chewieControllers`. This provides a list of all `ChewieController`s being used by `Html` widgets. - -5. `Html.videoPlayerControllers`. This provides a list of all `VideoPlayerController`s being used for video widgets by `Html` widgets. - -6. `Html.audioPlayerControllers`. This provides a list of all `VideoPlayerController`s being used for audio widgets by `Html` widgets. - -### Data: - -The HTML data passed to the `Html` widget as a `String`. This is required and cannot be null when using `Html`. -Any HTML tags in the `String` that are not supported by the package will not be rendered. - -#### Example Usage - Data: - -```dart -Widget html = Html( - data: """This is a fantastic product that you should buy!
-This is a fantastic product that you should buy!
-- Linking to websites has never been easier. -
""", - onLinkTap: (String? url, RenderContext context, MapJanuary | February | March | April | May | June | July | August | September | October | November | December |
---|---|---|---|---|---|---|---|---|---|---|---|
\$100 | \$50 | \$80 | \$60 | \$90 | \$140 | \$110 | \$80 | \$90 | \$60 | \$40 | \$70 |
\90 | \$60 | \$80 | \$80 | \$100 | \$160 | \$150 | \$110 | \$100 | \$60 | \$30 | \$80 |