SelectableHtml constructor

SelectableHtml({
  1. Key? key,
  2. required String? data,
  3. OnTap? onLinkTap,
  4. OnTap? onAnchorTap,
  5. OnCssParseError? onCssParseError,
  6. bool shrinkWrap = false,
  7. Map<String, Style> style = const {},
  8. List<String> tagsList = const [],
})

The SelectableHtml widget takes HTML as input and displays a RichText tree of the parsed HTML content (which is selectable)

Attributes data required takes in a String of HTML data (required only for Html constructor). document required takes in a Document of HTML data (required only for Html.fromDom constructor).

onLinkTap This function is called whenever a link (<a href>) is tapped.

onAnchorTap This function is called whenever an anchor (#anchor-id) is tapped.

tagsList Tag names in this array will be the only tags rendered. By default all tags that support selectable content are rendered.

style Pass in the style information for the Html here. See its wiki page for more info.

PLEASE NOTE

There are a few caveats due to Flutter #38474:

  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 because they all require widgets and WidgetSpans.

  2. No support for customRender, customImageRender, onImageError, onImageTap, onMathError, and navigationDelegateForIframe.

  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 because we can't use the ContainerSpan class (it needs an enclosing WidgetSpan).

Implementation

SelectableHtml({
  Key? key,
  required this.data,
  this.onLinkTap,
  this.onAnchorTap,
  this.onCssParseError,
  this.shrinkWrap = false,
  this.style = const {},
  this.tagsList = const [],
})  : document = null,
      super(key: key);