SelectableHtml constructor
- Key? key,
- GlobalKey<
State< ? anchorKey,StatefulWidget> > - required String? data,
- OnTap? onLinkTap,
- OnTap? onAnchorTap,
- OnCssParseError? onCssParseError,
- bool shrinkWrap = false,
- Map<
String, CSS3> style = const {}, - Map<
CustomRenderMatcher, SelectableCustomRender> customRenders = const {}, - List<
String> tagsList = const [], - TextSelectionControls? selectionControls,
- ScrollPhysics? scrollPhysics,
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). documentElement required
takes in a Element of HTML data (required only for Html.fromDom
and Html.fromElement
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.
for more info.
PLEASE NOTE There are a few caveats due to Flutter #38474:
-
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
WidgetSpan
s. -
No support for
customRender
,customImageRender
,onImageError
,onImageTap
,onMathError
, andnavigationDelegateForIframe
. -
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 enclosingWidgetSpan
).
Implementation
SelectableHtml({
Key? key,
GlobalKey? anchorKey,
required this.data,
this.onLinkTap,
this.onAnchorTap,
this.onCssParseError,
this.shrinkWrap = false,
this.style = const {},
this.customRenders = const {},
this.tagsList = const [],
this.selectionControls,
this.scrollPhysics,
}) : documentElement = null,
assert(data != null),
_anchorKey = anchorKey ?? GlobalKey(),
super(key: key);