Beispiel #1
0
        public override Widget build(BuildContext context)
        {
            base.build(context); // See AutomaticKeepAliveClientMixin.
            D.assert(MaterialD.debugCheckHasMaterial(context));
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            D.assert(
                !(this.widget.style != null && this.widget.style.inherit == false &&
                  (this.widget.style.fontSize == null || this.widget.style.textBaseline == null)),
                "inherit false style must supply fontSize and textBaseline"
                );
            ThemeData                 themeData          = Theme.of(context);
            TextStyle                 style              = themeData.textTheme.subhead.merge(this.widget.style);
            Brightness                keyboardAppearance = this.widget.keyboardAppearance ?? themeData.primaryColorBrightness;
            TextEditingController     controller         = this._effectiveController;
            FocusNode                 focusNode          = this._effectiveFocusNode;
            List <TextInputFormatter> formatters         = this.widget.inputFormatters ?? new List <TextInputFormatter>();

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

            bool forcePressEnabled = false;
            TextSelectionControls textSelectionControls = MaterialUtils.materialTextSelectionControls;;
            bool   paintCursorAboveText  = false;
            bool   cursorOpacityAnimates = false;
            Offset cursorOffset          = null;
            Color  cursorColor           = this.widget.cursorColor ?? themeData.cursorColor;
            Radius cursorRadius          = this.widget.cursorRadius;

            Widget child = new RepaintBoundary(
                child: new EditableText(
                    key: this._editableTextKey,
                    controller: controller,
                    focusNode: focusNode,
                    keyboardType: this.widget.keyboardType,
                    textInputAction: this.widget.textInputAction,
                    textCapitalization: this.widget.textCapitalization,
                    style: style,
                    textAlign: this.widget.textAlign,
                    textDirection: this.widget.textDirection,
                    autofocus: this.widget.autofocus,
                    obscureText: this.widget.obscureText,
                    autocorrect: this.widget.autocorrect,
                    maxLines: this.widget.maxLines,
                    selectionColor: themeData.textSelectionColor,
                    selectionControls: this.widget.selectionEnabled ? textSelectionControls : null,
                    onChanged: this.widget.onChanged,
                    onSelectionChanged: this._handleSelectionChanged,
                    onEditingComplete: this.widget.onEditingComplete,
                    onSubmitted: this.widget.onSubmitted,
                    inputFormatters: formatters,
                    rendererIgnoresPointer: true,
                    cursorWidth: this.widget.cursorWidth,
                    cursorRadius: cursorRadius,
                    cursorColor: cursorColor,
                    cursorOpacityAnimates: cursorOpacityAnimates,
                    cursorOffset: cursorOffset,
                    paintCursorAboveText: paintCursorAboveText,
                    backgroundCursorColor: new Color(0xFF8E8E93),// TODO: CupertinoColors.inactiveGray,
                    scrollPadding: this.widget.scrollPadding,
                    keyboardAppearance: keyboardAppearance,
                    enableInteractiveSelection: this.widget.enableInteractiveSelection == true,
                    dragStartBehavior: this.widget.dragStartBehavior
                    )
                );

            if (this.widget.decoration != null)
            {
                child = new AnimatedBuilder(
                    animation: ListenableUtils.merge(new List <Listenable> {
                    focusNode, controller
                }),
                    builder:
                    (_context, _child) => {
                    return(new InputDecorator(
                               decoration: this._getEffectiveDecoration(),
                               baseStyle: this.widget.style,
                               textAlign: this.widget.textAlign,
                               isFocused: focusNode.hasFocus,
                               isEmpty: controller.value.text.isEmpty(),
                               child: _child
                               ));
                },
                    child: child
                    );
            }

            return(new IgnorePointer(
                       ignoring: !(this.widget.enabled ?? this.widget.decoration?.enabled ?? true),
                       child: new TextSelectionGestureDetector(
                           onTapDown: this._handleTapDown,
                           // onForcePressStart: forcePressEnabled ? this._handleForcePressStarted : null, // TODO: Remove this when force press is added
                           onSingleTapUp: this._handleSingleTapUp,
                           onSingleTapCancel: this._handleSingleTapCancel,
                           onSingleLongTapStart: this._handleLongPress,
                           onDragSelectionStart: this._handleDragSelectionStart,
                           onDragSelectionUpdate: this._handleDragSelectionUpdate,
                           behavior: HitTestBehavior.translucent,
                           child: child
                           )
                       ));
        }
Beispiel #2
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterial(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);
            TextStyle                 style              = themeData.textTheme.subtitle1.merge(widget.style);
            Brightness                keyboardAppearance = widget.keyboardAppearance ?? themeData.primaryColorBrightness;
            TextEditingController     controller         = _effectiveController;
            FocusNode                 focusNode          = _effectiveFocusNode;
            List <TextInputFormatter> formatters         = widget.inputFormatters ?? new List <TextInputFormatter>();

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

            TextSelectionControls textSelectionControls = MaterialUtils.materialTextSelectionControls;

            ;
            bool   paintCursorAboveText  = false;
            bool   cursorOpacityAnimates = false;
            Offset cursorOffset          = null;
            Color  cursorColor           = widget.cursorColor ?? themeData.cursorColor;
            Radius cursorRadius          = widget.cursorRadius;

            _forcePressEnabled    = false;
            textSelectionControls = _MaterialTextSelectionControls.materialTextSelectionControls;
            paintCursorAboveText  = false;
            cursorOpacityAnimates = false;
            cursorColor           = cursorColor ?? themeData.cursorColor;

            Widget child = new RepaintBoundary(
                child: new EditableText(
                    key: editableTextKey,
                    readOnly: widget.readOnly,
                    toolbarOptions: widget.toolbarOptions,
                    showCursor: widget.showCursor,
                    showSelectionHandles: _showSelectionHandles,
                    controller: controller,
                    focusNode: focusNode,
                    keyboardType: widget.keyboardType,
                    textInputAction: widget.textInputAction,
                    textCapitalization: widget.textCapitalization,
                    style: style,
                    strutStyle: widget.strutStyle,
                    textAlign: widget.textAlign,
                    textDirection: widget.textDirection,
                    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: themeData.textSelectionColor,
                    selectionControls: widget.selectionEnabled ? textSelectionControls : null,
                    onChanged: widget.onChanged,
                    onSelectionChanged: _handleSelectionChanged,
                    onEditingComplete: widget.onEditingComplete,
                    onSubmitted: widget.onSubmitted,
                    onSelectionHandleTapped: _handleSelectionHandleTapped,
                    inputFormatters: formatters,
                    rendererIgnoresPointer: true,
                    cursorWidth: widget.cursorWidth.Value,
                    cursorRadius: cursorRadius,
                    cursorColor: cursorColor,
                    selectionHeightStyle: widget.selectionHeightStyle,
                    selectionWidthStyle: widget.selectionWidthStyle,
                    cursorOpacityAnimates: cursorOpacityAnimates,
                    cursorOffset: cursorOffset,
                    paintCursorAboveText: paintCursorAboveText,
                    backgroundCursorColor: CupertinoColors.inactiveGray,
                    scrollPadding: widget.scrollPadding,
                    keyboardAppearance: keyboardAppearance,
                    enableInteractiveSelection: widget.enableInteractiveSelection == true,
                    dragStartBehavior: widget.dragStartBehavior,
                    scrollController: widget.scrollController,
                    scrollPhysics: widget.scrollPhysics
                    )
                );

            if (widget.decoration != null)
            {
                child = new AnimatedBuilder(
                    animation: ListenableUtils.merge(new List <Listenable> {
                    focusNode, controller
                }),
                    builder:
                    (_context, _child) => {
                    return(new InputDecorator(
                               decoration: _getEffectiveDecoration(),
                               baseStyle: widget.style,
                               textAlign: widget.textAlign,
                               textAlignVertical: widget.textAlignVertical,
                               isHovering: _isHovering,
                               isFocused: focusNode.hasFocus,
                               isEmpty: controller.value.text.isEmpty(),
                               expands: widget.expands,
                               child: _child
                               ));
                },
                    child: child
                    );
            }

            void onEnter(PointerEnterEvent pEvent)
            {
                _handleHover(true);
            }

            void onExit(PointerExitEvent pEvent)
            {
                _handleHover(false);
            }

            return(new IgnorePointer(
                       ignoring: !_isEnabled,
                       child: new MouseRegion(
                           onEnter: onEnter,
                           onExit: onExit,
                           child: new AnimatedBuilder(
                               animation: controller,
                               builder: (BuildContext buildContext, Widget buildChild) => { return buildChild; },
                               child: _selectionGestureDetectorBuilder.buildGestureDetector(
                                   behavior: HitTestBehavior.translucent,
                                   child: child
                                   )
                               )
                           )
                       ));
        }