WidgetSpan class

An immutable widget that is embedded inline within text.

The child property is the widget that will be embedded. Children are constrained by the width of the paragraph.

The child property may contain its own Widget children (if applicable), including Text and RichText widgets which may include additional WidgetSpans. Child Text and RichText widgets will be laid out independently and occupy a rectangular space in the parent text layout.

WidgetSpans will be ignored when passed into a TextPainter directly. To properly layout and paint the child widget, WidgetSpan should be passed into a Text.rich widget.

A card with Hello World! embedded inline within a TextSpan tree.
Text.rich(
  TextSpan(
    children: <InlineSpan>[
      TextSpan(text: 'Flutter is'),
      WidgetSpan(
        child: SizedBox(
          width: 120,
          height: 50,
          child: Card(
            child: Center(
              child: Text('Hello World!')
            )
          ),
        )
      ),
      TextSpan(text: 'the best!'),
    ],
  )
)

WidgetSpan contributes the semantics of the WidgetSpan.child to the semantics tree.

See also:

Inheritance
Annotations
  • @immutable

Constructors

WidgetSpan({@required Widget child, PlaceholderAlignment alignment: ui.PlaceholderAlignment.bottom, TextBaseline baseline, TextStyle style })
Creates a WidgetSpan with the given values. [...]
const

Properties

child Widget
The widget to embed inline within text.
final
hashCode int
The hash code for this object. [...]
read-only, override
alignment PlaceholderAlignment
How the placeholder aligns vertically with the text. [...]
final, inherited
baseline TextBaseline
The TextBaseline to align against when using ui.PlaceholderAlignment.baseline, ui.PlaceholderAlignment.aboveBaseline, and ui.PlaceholderAlignment.belowBaseline. [...]
final, inherited
children List<InlineSpan>
Returns the InlineSpan children list associated with this span if this is an instance of TextSpan, otherwise returns null.
@Deprecated('InlineSpan does not innately have children. Use TextSpan.children instead.'), read-only, inherited
recognizer GestureRecognizer
Returns the GestureRecognizer associated with this span if this is an instance of TextSpan, otherwise returns null.
@Deprecated('InlineSpan does not innately have a recognizer. Use TextSpan.recognizer instead.'), read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
style TextStyle
The TextStyle to apply to this span. [...]
final, inherited
text String
Returns the text associated with this span if this is an instance of TextSpan, otherwise returns null.
@Deprecated('InlineSpan does not innately have text. Use TextSpan.text instead.'), read-only, inherited

Methods

build(ParagraphBuilder builder, { double textScaleFactor: 1.0, List<PlaceholderDimensions> dimensions }) → void
Adds a placeholder box to the paragraph builder if a size has been calculated for the widget. [...]
override
codeUnitAtVisitor(int index, Accumulator offset) int
Performs the check at each InlineSpan for if the index falls within the range of the span and returns the corresponding code unit. Returns null otherwise. [...]
override
compareTo(InlineSpan other) RenderComparison
Describe the difference between this span and another, in terms of how much damage it will make to the rendering. The comparison is deep. [...]
override
debugAssertIsValid() bool
In debug mode, throws an exception if the object is not in a valid configuration. Otherwise, returns true. [...]
override
getSpanForPosition(TextPosition position) InlineSpan
Returns the text span that contains the given position in the text.
override
getSpanForPositionVisitor(TextPosition position, Accumulator offset) InlineSpan
Performs the check at each InlineSpan for if the position falls within the range of the span and returns the span if it does. [...]
override
visitChildren(InlineSpanVisitor visitor) bool
Calls visitor on this WidgetSpan. There are no children spans to walk.
override
codeUnitAt(int index) int
Returns the UTF-16 code unit at the given index in the flattened string. [...]
inherited
computeToPlainText(StringBuffer buffer, { bool includeSemanticsLabels: true, bool includePlaceholders: true }) → void
PlaceholderSpans are flattened to a 0xFFFC object replacement character in the plain text representation when includePlaceholders is true.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children. [...]
@protected, inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node. [...]
inherited
describeSemantics(Accumulator offset, List<int> semanticsOffsets, List semanticsElements) → void
Populates the semanticsOffsets and semanticsElements with the appropriate data to be able to construct a SemanticsNode. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toDiagnosticsNode({String name, DiagnosticsTreeStyle style }) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep. [...]
inherited
toPlainText({bool includeSemanticsLabels: true, bool includePlaceholders: true }) String
Flattens the InlineSpan tree into a single string. [...]
inherited
toString({DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this object.
inherited
toStringDeep({String prefixLineOne: '', String prefixOtherLines, DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a string representation of this node and its descendants. [...]
inherited
toStringShallow({String joiner: ', ', DiagnosticLevel minLevel: DiagnosticLevel.debug }) String
Returns a one-line detailed description of the object. [...]
inherited
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode. [...]
inherited
visitTextSpan(bool visitor(TextSpan span)) bool
The visitTextSpan method is invalid on PlaceholderSpans
@Deprecated('Use to visitChildren instead'), inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
override