Example #1
0
 public static Widget merge(
     Widget child,
     Key key                                  = null,
     TextStyle style                          = null,
     TextAlign?textAlign                      = null,
     bool?softWrap                            = null,
     TextOverflow?overflow                    = null,
     int?maxLines                             = null,
     TextWidthBasis?textWidthBasis            = null,
     ui.TextHeightBehavior textHeightBehavior = null
     )
 {
     D.assert(child != null);
     return(new Builder(
                builder: (BuildContext context) => {
         DefaultTextStyle parent = DefaultTextStyle.of(context);
         return new DefaultTextStyle(
             key: key,
             style: parent.style.merge(style),
             textAlign: textAlign ?? parent.textAlign,
             softWrap: softWrap ?? parent.softWrap,
             overflow: overflow ?? parent.overflow,
             maxLines: maxLines ?? parent.maxLines,
             textWidthBasis: textWidthBasis ?? parent.textWidthBasis,
             child: child
             );
     }
                ));
 }
Example #2
0
        public override Widget build(BuildContext context)
        {
            DefaultTextStyle defaultTextStyle   = DefaultTextStyle.of(context);
            TextStyle        effectiveTextStyle = this.style;

            if (this.style == null || this.style.inherit)
            {
                effectiveTextStyle = defaultTextStyle.style.merge(this.style);
            }

            return(new RichText(
                       textAlign: this.textAlign ?? defaultTextStyle.textAlign ?? TextAlign.left,
                       softWrap: this.softWrap ?? defaultTextStyle.softWrap,
                       overflow: this.overflow ?? defaultTextStyle.overflow,
                       textScaleFactor: this.textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
                       maxLines: this.maxLines ?? defaultTextStyle.maxLines,
                       strutStyle: this.strutStyle,
                       text: new TextSpan(
                           style: effectiveTextStyle,
                           text: this.data,
                           children: this.textSpan != null ? new List <TextSpan> {
                this.textSpan
            } : null
                           )
                       ));
        }
Example #3
0
        public override Widget build(BuildContext context)
        {
            DefaultTextStyle defaultTextStyle   = DefaultTextStyle.of(context);
            TextStyle        effectiveTextStyle = style;

            if (style == null || style.inherit)
            {
                effectiveTextStyle = defaultTextStyle.style.merge(style);
            }

            return(new RichText(
                       textAlign: textAlign ?? defaultTextStyle.textAlign ?? TextAlign.left,
                       softWrap: softWrap ?? defaultTextStyle.softWrap,
                       overflow: overflow ?? defaultTextStyle.overflow,
                       textScaleFactor: textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
                       maxLines: maxLines ?? defaultTextStyle.maxLines,
                       strutStyle: strutStyle,
                       textWidthBasis: textWidthBasis ?? defaultTextStyle.textWidthBasis,
                       textHeightBehavior: textHeightBehavior ?? defaultTextStyle.textHeightBehavior,
                       text: new TextSpan(
                           style: effectiveTextStyle,
                           text: data,
                           children: textSpan != null ? new List <InlineSpan> {
                textSpan
            } : null
                           )
                       ));
        }
Example #4
0
        public override Widget build(BuildContext context)
        {
            FocusScope.of(context).reparentIfNeeded(this.widget.focusNode);

            DefaultTextStyle defaultTextStyle   = DefaultTextStyle.of(context);
            TextStyle        effectiveTextStyle = this.widget.style;

            if (this.widget.style == null || this.widget.style.inherit)
            {
                effectiveTextStyle = defaultTextStyle.style.merge(this.widget.style);
            }

            Widget child = new RichText(
                key: this._richTextKey,
                textAlign: this.widget.textAlign ?? defaultTextStyle.textAlign ?? TextAlign.left,
                softWrap: this.widget.softWrap ?? defaultTextStyle.softWrap,
                overflow: this.widget.overflow ?? defaultTextStyle.overflow,
                textScaleFactor: this.widget.textScaleFactor ?? MediaQuery.textScaleFactorOf(context),
                maxLines: this.widget.maxLines ?? defaultTextStyle.maxLines,
                text: new TextSpan(
                    style: effectiveTextStyle,
                    text: this.widget.data,
                    children: this.widget.textSpan != null ? new List <TextSpan> {
                this.widget.textSpan
            } : null
                    ),
                onSelectionChanged: () => {
                if (this._hasFocus)
                {
                    return;
                }

                FocusScope.of(this.context).requestFocus(this.widget.focusNode);
            },
                selectionColor: this.widget.selectionColor ?? Colors.blue);

            return(new IgnorePointer(
                       ignoring: false,
                       child: new RichTextSelectionGestureDetector(
                           onTapDown: this._handleTapDown,
                           onSingleTapUp: this._handleSingleTapUp,
                           onSingleTapCancel: this._handleSingleTapCancel,
                           onSingleLongTapStart: this._handleLongPress,
                           onDragSelectionStart: this._handleDragSelectionStart,
                           onDragSelectionUpdate: this._handleDragSelectionUpdate,
                           behavior: HitTestBehavior.translucent,
                           child: child
                           )
                       ));
        }