예제 #1
0
        public override Widget build(BuildContext context)
        {
            base.build(context);
            D.assert(() => { return(_controller._textSpan.visitChildren((InlineSpan span) => span is TextSpan)); },
                     () => "SelectableText only supports TextSpan; Other type of InlineSpan is not allowed");
            D.assert(WidgetsD.debugCheckHasMediaQuery(context));
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            D.assert(
                !(widget.style != null && widget.style.inherit == false &&
                  (widget.style.fontSize == null || widget.style.textBaseline == null)),
                () => "inherit false style must supply fontSize and textBaseline"
                );

            ThemeData themeData = Theme.of(context);
            FocusNode focusNode = _effectiveFocusNode;

            TextSelectionControls textSelectionControls;
            bool   paintCursorAboveText;
            bool   cursorOpacityAnimates;
            Offset cursorOffset = Offset.zero;
            Color  cursorColor  = widget.cursorColor;
            Radius cursorRadius = widget.cursorRadius;

            switch (themeData.platform)
            {
            case RuntimePlatform.IPhonePlayer:
            case RuntimePlatform.OSXEditor:
            case RuntimePlatform.OSXPlayer:
                forcePressEnabled     = true;
                textSelectionControls = CupertinoTextFieldUtils.cupertinoTextSelectionControls;
                paintCursorAboveText  = true;
                cursorOpacityAnimates = true;
                cursorColor           = cursorColor ?? CupertinoTheme.of(context).primaryColor;
                cursorRadius          = cursorRadius ?? Radius.circular(2.0f);
                cursorOffset          =
                    new Offset(SelectableTextUtils.iOSHorizontalOffset / MediaQuery.of(context).devicePixelRatio,
                               0);
                break;

            default:
                forcePressEnabled     = false;
                textSelectionControls = _MaterialTextSelectionControls.materialTextSelectionControls;
                paintCursorAboveText  = false;
                cursorOpacityAnimates = false;
                cursorColor           = cursorColor ?? themeData.cursorColor;
                break;
            }

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

            if (widget.style == null || widget.style.inherit)
            {
                effectiveTextStyle = defaultTextStyle.style.merge(widget.style);
            }
            if (MediaQuery.boldTextOverride(context))
            {
                effectiveTextStyle = effectiveTextStyle.merge(new TextStyle(fontWeight: FontWeight.bold));
            }

            Widget child = new RepaintBoundary(
                child: new EditableText(
                    key: editableTextKey,
                    style: effectiveTextStyle,
                    readOnly: true,
                    textWidthBasis: widget.textWidthBasis ?? defaultTextStyle.textWidthBasis,
                    showSelectionHandles: _showSelectionHandles,
                    showCursor: widget.showCursor,
                    controller: _controller,
                    focusNode: focusNode,
                    strutStyle: widget.strutStyle ?? new StrutStyle(),
                    textAlign: widget.textAlign ?? defaultTextStyle.textAlign ?? TextAlign.start,
                    textDirection: widget.textDirection,
                    textScaleFactor: widget.textScaleFactor,
                    autofocus: widget.autofocus,
                    forceLine: false,
                    toolbarOptions: widget.toolbarOptions,
                    minLines: widget.minLines,
                    maxLines: widget.maxLines ?? defaultTextStyle.maxLines,
                    selectionColor: themeData.textSelectionColor,
                    selectionControls: widget.selectionEnabled ? textSelectionControls : null,
                    onSelectionChanged: _handleSelectionChanged,
                    onSelectionHandleTapped: _handleSelectionHandleTapped,
                    rendererIgnoresPointer: true,
                    cursorWidth: widget.cursorWidth,
                    cursorRadius: cursorRadius,
                    cursorColor: cursorColor,
                    cursorOpacityAnimates: cursorOpacityAnimates,
                    cursorOffset: cursorOffset,
                    paintCursorAboveText: paintCursorAboveText,
                    backgroundCursorColor: CupertinoColors.inactiveGray,
                    enableInteractiveSelection: widget.enableInteractiveSelection,
                    dragStartBehavior: widget.dragStartBehavior,
                    scrollPhysics: widget.scrollPhysics
                    )
                );

            return(_selectionGestureDetectorBuilder.buildGestureDetector(
                       behavior: HitTestBehavior.translucent,
                       child: child
                       ));
        }
예제 #2
0
        public override Widget build(BuildContext context)
        {
            base.build(context);
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            TextEditingController     controller = _effectiveController;
            List <TextInputFormatter> formatters = widget.inputFormatters ?? new List <TextInputFormatter>();
            bool   enabled      = widget.enabled ?? true;
            Offset cursorOffset =
                new Offset(
                    CupertinoTextFieldUtils._iOSHorizontalCursorOffsetPixels / MediaQuery.of(context).devicePixelRatio,
                    0);

            if (widget.maxLength != null && widget.maxLengthEnforced)
            {
                formatters.Add(new LengthLimitingTextInputFormatter(widget.maxLength));
            }

            CupertinoThemeData themeData     = CupertinoTheme.of(context);
            TextStyle          resolvedStyle = widget.style?.copyWith(
                color: CupertinoDynamicColor.resolve(widget.style?.color, context),
                backgroundColor: CupertinoDynamicColor.resolve(widget.style?.backgroundColor, context)
                );
            TextStyle textStyle = themeData.textTheme.textStyle.merge(resolvedStyle);
            TextStyle resolvedPlaceholderStyle = widget.placeholderStyle?.copyWith(
                color: CupertinoDynamicColor.resolve(widget.placeholderStyle?.color, context),
                backgroundColor: CupertinoDynamicColor.resolve(widget.placeholderStyle?.backgroundColor, context)
                );
            TextStyle  placeholderStyle   = textStyle.merge(resolvedPlaceholderStyle);
            Brightness?keyboardAppearance = widget.keyboardAppearance ?? CupertinoTheme.brightnessOf(context);

            Color cursorColor   = CupertinoDynamicColor.resolve(widget.cursorColor, context) ?? themeData.primaryColor;
            Color disabledColor = CupertinoDynamicColor.resolve(CupertinoTextFieldUtils._kDisabledBackground, context);

            Color     decorationColor = CupertinoDynamicColor.resolve(widget.decoration?.color, context);
            BoxBorder border          = widget.decoration?.border;
            Border    resolvedBorder  = border as Border;

            if (border is Border)
            {
                BorderSide resolveBorderSide(BorderSide side)
                {
                    return(side == BorderSide.none
                        ? side
                        : side.copyWith(color: CupertinoDynamicColor.resolve(side.color, context)));
                }

                resolvedBorder = (Border)(border == null || border.GetType() != typeof(Border)
                    ? border
                    : new Border(
                                              top: resolveBorderSide(((Border)border).top),
                                              left: resolveBorderSide(((Border)border).left),
                                              bottom: resolveBorderSide(((Border)border).bottom),
                                              right: resolveBorderSide(((Border)border).right)
                                              ));
            }

            BoxDecoration effectiveDecoration = widget.decoration?.copyWith(
                border: resolvedBorder,
                color: enabled ? decorationColor : (decorationColor == null ? disabledColor : decorationColor)
                );

            Widget paddedEditable = new Padding(
                padding: widget.padding,
                child: new RepaintBoundary(
                    child: new EditableText(
                        key: editableTextKey,
                        controller: controller,
                        readOnly: widget.readOnly,
                        toolbarOptions: widget.toolbarOptions,
                        showCursor: widget.showCursor,
                        showSelectionHandles: _showSelectionHandles,
                        focusNode: _effectiveFocusNode,
                        keyboardType: widget.keyboardType,
                        textInputAction: widget.textInputAction,
                        textCapitalization: widget.textCapitalization,
                        style: textStyle,
                        strutStyle: widget.strutStyle,
                        textAlign: widget.textAlign,
                        autofocus: widget.autofocus,
                        obscureText: widget.obscureText,
                        autocorrect: widget.autocorrect,
                        smartDashesType: widget.smartDashesType,
                        smartQuotesType: widget.smartQuotesType,
                        enableSuggestions: widget.enableSuggestions,
                        maxLines: widget.maxLines,
                        minLines: widget.minLines,
                        expands: widget.expands,
                        selectionColor: CupertinoTheme.of(context).primaryColor.withOpacity(0.2f),
                        selectionControls: widget.selectionEnabled
                        ? CupertinoTextFieldUtils.cupertinoTextSelectionControls : null,
                        onChanged: widget.onChanged,
                        onSelectionChanged: _handleSelectionChanged,
                        onEditingComplete: widget.onEditingComplete,
                        onSubmitted: widget.onSubmitted,
                        inputFormatters: formatters,
                        rendererIgnoresPointer: true,
                        cursorWidth: widget.cursorWidth,
                        cursorRadius: widget.cursorRadius,
                        cursorColor: cursorColor,
                        cursorOpacityAnimates: true,
                        cursorOffset: cursorOffset,
                        paintCursorAboveText: true,
                        backgroundCursorColor: CupertinoDynamicColor.resolve(CupertinoColors.inactiveGray, context),
                        selectionHeightStyle: widget.selectionHeightStyle,
                        selectionWidthStyle: widget.selectionWidthStyle,
                        scrollPadding: widget.scrollPadding,
                        keyboardAppearance: keyboardAppearance,
                        dragStartBehavior: widget.dragStartBehavior,
                        scrollController: widget.scrollController,
                        scrollPhysics: widget.scrollPhysics,
                        enableInteractiveSelection: widget.enableInteractiveSelection
                        )
                    )
                );

            return(new IgnorePointer(
                       ignoring: !enabled,
                       child: new Container(
                           decoration: effectiveDecoration,
                           child: _selectionGestureDetectorBuilder.buildGestureDetector(
                               behavior: HitTestBehavior.translucent,
                               child: new Align(
                                   alignment: new Alignment(-1.0f, _textAlignVertical.y),
                                   widthFactor: 1.0f,
                                   heightFactor: 1.0f,
                                   child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle)
                                   )
                               )
                           )

                       ));
        }
예제 #3
0
            public override Widget build(BuildContext context)
            {
                var children = new List <Widget>
                {
                    new Container(
                        margin: EdgeInsets.only(top: 24f, bottom: 16.0f),
                        child: new Text(
                            "文章导览",
                            style: ItemStyle.merge(
                                new TextStyle(
                                    fontWeight: FontWeight.w500,
                                    color: new Color(0xff212121)
                                    )
                                )
                            )
                        )
                };

                children.AddRange(
                    _items.Select <PositionRecord, Widget>(
                        Item => new Clickable(
                            onTap: () => _controller.animateTo(
                                _controller.position.pixels - Item.getPosition.Invoke() - 96,
                                new TimeSpan(0, 0, 0, 0, 240),
                                curve: Curves.easeInOut)
                            ,
                            child: new Container(
                                margin: EdgeInsets.only(bottom: 16.0f),
                                child: new Text(
                                    Item.title,
                                    style: ItemStyle
                                    )
                                )
                            )
                        )
                    );
                return(new Container(
                           padding: EdgeInsets.only(
                               left: 48.0f,
                               right: 48.0f
                               ),
                           width: 324.0f,
                           child: new Column(
                               crossAxisAlignment: CrossAxisAlignment.stretch,
                               children: new List <Widget>
                {
                    new Container(
                        height: 64f,
                        padding: EdgeInsets.only(bottom: 8.0f),
                        child: new Align(
                            alignment: Alignment.bottomLeft,
                            child: new Clickable(
                                onTap: () => LocationUtil.HrefTo(_githubLink),
                                child: new Row(
                                    children: new List <Widget>
                    {
                        new Container(
                            margin: EdgeInsets.only(right: 8),
                            child: new Icon(
                                Icons.BrandsGithub,
                                color: new Color(0xff000000),
                                size: 24f
                                )
                            ),
                        new Text(
                            "在Github上编辑本文",
                            style: new TextStyle(
                                fontSize: 16,
                                decoration: TextDecoration.underline,
                                color: new Color(0xff2196f3)
                                )
                            )
                    }
                                    )
                                )
                            )
                        ),
                    new Container(
                        height: 1f,
                        color: DividerColor
                        ),
                    new Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: children
                        )
                }
                               )
                           ));
            }
예제 #4
0
        public override Widget build(BuildContext context)
        {
            base.build(context);
            TextEditingController     controller = this._effectiveController;
            List <TextInputFormatter> formatters = this.widget.inputFormatters ?? new List <TextInputFormatter>();
            bool   enabled      = this.widget.enabled ?? true;
            Offset cursorOffset =
                new Offset(
                    CupertinoTextFieldUtils._iOSHorizontalCursorOffsetPixels / MediaQuery.of(context).devicePixelRatio,
                    0);

            if (this.widget.maxLength != null && this.widget.maxLengthEnforced)
            {
                formatters.Add(new LengthLimitingTextInputFormatter(this.widget.maxLength));
            }

            CupertinoThemeData themeData          = CupertinoTheme.of(context);
            TextStyle          textStyle          = themeData.textTheme.textStyle.merge(this.widget.style);
            TextStyle          placeholderStyle   = textStyle.merge(this.widget.placeholderStyle);
            Brightness         keyboardAppearance = this.widget.keyboardAppearance ?? themeData.brightness;
            Color cursorColor = this.widget.cursorColor ?? themeData.primaryColor;

            Widget paddedEditable = new Padding(
                padding: this.widget.padding,
                child: new RepaintBoundary(
                    child: new EditableText(
                        key: this._editableTextKey,
                        controller: controller,
                        focusNode: this._effectiveFocusNode,
                        keyboardType: this.widget.keyboardType,
                        textInputAction: this.widget.textInputAction,
                        textCapitalization: this.widget.textCapitalization,
                        style: textStyle,
                        strutStyle: this.widget.strutStyle,
                        textAlign: this.widget.textAlign,
                        autofocus: this.widget.autofocus,
                        obscureText: this.widget.obscureText,
                        autocorrect: this.widget.autocorrect,
                        maxLines: this.widget.maxLines,
                        minLines: this.widget.minLines,
                        expands: this.widget.expands,
                        selectionColor: CupertinoTextFieldUtils._kSelectionHighlightColor,
                        selectionControls: CupertinoTextSelectionUtils.cupertinoTextSelectionControls,
                        onChanged: this.widget.onChanged,
                        onSelectionChanged: this._handleSelectionChanged,
                        onEditingComplete: this.widget.onEditingComplete,
                        onSubmitted: this.widget.onSubmitted,
                        inputFormatters: formatters,
                        rendererIgnoresPointer: true,
                        cursorWidth: this.widget.cursorWidth,
                        cursorRadius: this.widget.cursorRadius,
                        cursorColor: cursorColor,
                        cursorOpacityAnimates: true,
                        cursorOffset: cursorOffset,
                        paintCursorAboveText: true,
                        backgroundCursorColor: CupertinoColors.inactiveGray,
                        scrollPadding: this.widget.scrollPadding,
                        keyboardAppearance: keyboardAppearance,
                        dragStartBehavior: this.widget.dragStartBehavior,
                        scrollPhysics: this.widget.scrollPhysics
                        )
                    )
                );

            return(new IgnorePointer(
                       ignoring: !enabled,
                       child: new Container(
                           decoration: this.widget.decoration,
                           child: new Container(
                               color: enabled
                            ? null
                            : CupertinoTheme.of(context).brightness == Brightness.light
                                ? CupertinoTextFieldUtils._kDisabledBackground
                                : CupertinoColors.darkBackgroundGray,
                               child: new TextSelectionGestureDetector(
                                   onTapDown: this._handleTapDown,
                                   onSingleTapUp: this._handleSingleTapUp,
                                   onSingleLongTapStart: this._handleSingleLongTapStart,
                                   onSingleLongTapMoveUpdate: this._handleSingleLongTapMoveUpdate,
                                   onSingleLongTapEnd: this._handleSingleLongTapEnd,
                                   onDoubleTapDown: this._handleDoubleTapDown,
                                   onDragSelectionStart: this._handleMouseDragSelectionStart,
                                   onDragSelectionUpdate: this._handleMouseDragSelectionUpdate,
                                   onDragSelectionEnd: this._handleMouseDragSelectionEnd,
                                   behavior: HitTestBehavior.translucent,
                                   child: this._addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle)
                                   )
                               )
                           )
                       ));
        }