Exemple #1
0
 public override bool debugCheckContext(BuildContext context)
 {
     D.assert(WidgetsD.debugCheckHasTable(context));
     return(base.debugCheckContext(context));
 }
Exemple #2
0
        public override Widget build(BuildContext context)
        {
            D.assert(WidgetsD.debugCheckHasMediaQuery(context));
            ThemeData theme     = Theme.of(context);
            TextStyle textStyle = theme.primaryTextTheme.subhead.copyWith(color: this.foregroundColor);
            Color     effectiveBackgroundColor = this.backgroundColor;

            if (effectiveBackgroundColor == null)
            {
                switch (ThemeData.estimateBrightnessForColor(textStyle.color))
                {
                case Brightness.dark:
                    effectiveBackgroundColor = theme.primaryColorLight;
                    break;

                case Brightness.light:
                    effectiveBackgroundColor = theme.primaryColorDark;
                    break;
                }
            }
            else if (this.foregroundColor == null)
            {
                switch (ThemeData.estimateBrightnessForColor(this.backgroundColor))
                {
                case Brightness.dark:
                    textStyle = textStyle.copyWith(color: theme.primaryColorLight);
                    break;

                case Brightness.light:
                    textStyle = textStyle.copyWith(color: theme.primaryColorDark);
                    break;
                }
            }

            float minDiameter = this._minDiameter;
            float maxDiameter = this._maxDiameter;

            return(new AnimatedContainer(
                       constraints: new BoxConstraints(
                           minHeight: minDiameter,
                           minWidth: minDiameter,
                           maxWidth: maxDiameter,
                           maxHeight: maxDiameter
                           ),
                       duration: Constants.kThemeChangeDuration,
                       decoration: new BoxDecoration(
                           color: effectiveBackgroundColor,
                           image: this.backgroundImage != null
                        ? new DecorationImage(image: this.backgroundImage, fit: BoxFit.cover)
                        : null,
                           shape: BoxShape.circle
                           ),
                       child: this.child == null
                    ? null
                    : new Center(
                           child: new MediaQuery(
                               data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0f),
                               child: new IconTheme(
                                   data: theme.iconTheme.copyWith(color: textStyle.color),
                                   child: new DefaultTextStyle(
                                       style: textStyle,
                                       child: this.child
                                       )
                                   )
                               )
                           )
                       ));
        }
        public override Widget buildPage(BuildContext context, Animation <float> animation,
                                         Animation <float> secondaryAnimation)
        {
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            float screenHeight  = MediaQuery.of(context).size.height;
            float maxMenuHeight = screenHeight - 2.0f * DropdownConstants._kMenuItemHeight;

            float buttonTop    = this.buttonRect.top;
            float buttonBottom = this.buttonRect.bottom;

            float topLimit    = Mathf.Min(DropdownConstants._kMenuItemHeight, buttonTop);
            float bottomLimit = Mathf.Max(screenHeight - DropdownConstants._kMenuItemHeight, buttonBottom);

            float?selectedItemOffset = this.selectedIndex * DropdownConstants._kMenuItemHeight +
                                       Constants.kMaterialListPadding.top;

            float?menuTop = (buttonTop - selectedItemOffset) -
                            (DropdownConstants._kMenuItemHeight - this.buttonRect.height) / 2.0f;
            float preferredMenuHeight = (this.items.Count * DropdownConstants._kMenuItemHeight) +
                                        Constants.kMaterialListPadding.vertical;

            float menuHeight = Mathf.Min(maxMenuHeight, preferredMenuHeight);

            float?menuBottom = menuTop + menuHeight;

            if (menuTop < topLimit)
            {
                menuTop = Mathf.Min(buttonTop, topLimit);
            }

            if (menuBottom > bottomLimit)
            {
                menuBottom = Mathf.Max(buttonBottom, bottomLimit);
                menuTop    = menuBottom - menuHeight;
            }

            if (this.scrollController == null)
            {
                float scrollOffset = preferredMenuHeight > maxMenuHeight
                    ? Mathf.Max(0.0f, selectedItemOffset ?? 0.0f - (buttonTop - (menuTop ?? 0.0f)))
                    : 0.0f;

                this.scrollController = new ScrollController(initialScrollOffset: scrollOffset);
            }

            Widget menu = new _DropdownMenu <T>(
                route: this,
                padding: this.padding
                );

            if (this.theme != null)
            {
                menu = new Theme(data: this.theme, child: menu);
            }

            return(MediaQuery.removePadding(
                       context: context,
                       removeTop: true,
                       removeBottom: true,
                       removeLeft: true,
                       removeRight: true,
                       child: new Builder(
                           builder: (BuildContext _context) => {
                return new CustomSingleChildLayout(
                    layoutDelegate: new _DropdownMenuRouteLayout <T>(
                        buttonRect: this.buttonRect,
                        menuTop: menuTop ?? 0.0f,
                        menuHeight: menuHeight
                        ),
                    child: menu
                    );
            }
                           )
                       ));
        }
        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; // TODO: wait for force press is ready
            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
                           )
                       ));
        }
Exemple #5
0
        public override Widget build(BuildContext context)
        {
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));

            ThemeData     theme    = Theme.of(context);
            List <Widget> children = new List <Widget> {
            };

            if (this.widget.accountName != null)
            {
                Widget accountNameLine = new LayoutId(
                    id: _AccountDetailsLayout.accountName,
                    child: new Padding(
                        padding: EdgeInsets.symmetric(vertical: 2.0f),
                        child: new DefaultTextStyle(
                            style: theme.primaryTextTheme.body2,
                            overflow: TextOverflow.ellipsis,
                            child: this.widget.accountName
                            )
                        )
                    );
                children.Add(accountNameLine);
            }

            if (this.widget.accountEmail != null)
            {
                Widget accountEmailLine = new LayoutId(
                    id: _AccountDetailsLayout.accountEmail,
                    child: new Padding(
                        padding: EdgeInsets.symmetric(vertical: 2.0f),
                        child: new DefaultTextStyle(
                            style: theme.primaryTextTheme.body1,
                            overflow: TextOverflow.ellipsis,
                            child: this.widget.accountEmail
                            )
                        )
                    );
                children.Add(accountEmailLine);
            }

            if (this.widget.onTap != null)
            {
                MaterialLocalizations localizations = MaterialLocalizations.of(context);
                Widget dropDownIcon = new LayoutId(
                    id: _AccountDetailsLayout.dropdownIcon,
                    child: new SizedBox(
                        height: UserAccountsDrawerHeaderUtils._kAccountDetailsHeight,
                        width: UserAccountsDrawerHeaderUtils._kAccountDetailsHeight,
                        child: new Center(
                            child: Transform.rotate(
                                degree: this._animation.value * Mathf.PI,
                                child: new Icon(
                                    Icons.arrow_drop_down,
                                    color: Colors.white
                                    )
                                )
                            )
                        )
                    );
                children.Add(dropDownIcon);
            }

            Widget accountDetails = new CustomMultiChildLayout(
                layoutDelegate: new _AccountDetailsLayout(),
                children: children
                );

            if (this.widget.onTap != null)
            {
                accountDetails = new InkWell(
                    onTap: this.widget.onTap == null ? (GestureTapCallback)null : () => { this.widget.onTap(); },
                    child: accountDetails
                    );
            }

            return(new SizedBox(
                       height: UserAccountsDrawerHeaderUtils._kAccountDetailsHeight,
                       child: accountDetails
                       ));
        }
Exemple #6
0
        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
                       ));
        }
Exemple #7
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)
                                   )
                               )
                           )

                       ));
        }
Exemple #8
0
        public override Widget buildToolbar(
            BuildContext context,
            Rect globalEditableRegion,
            float textLineHeight,
            Offset position,
            List <TextSelectionPoint> endpoints,
            TextSelectionDelegate _delegate
            )
        {
            D.assert(WidgetsD.debugCheckHasMediaQuery(context));
            MediaQueryData mediaQuery = MediaQuery.of(context);

            float toolbarHeightNeeded = mediaQuery.padding.top
                                        + CupertinoTextSelectionUtils._kToolbarScreenPadding
                                        + CupertinoTextSelectionUtils._kToolbarHeight
                                        + CupertinoTextSelectionUtils._kToolbarContentDistance;
            float availableHeight     = globalEditableRegion.top + endpoints.first().point.dy - textLineHeight;
            bool  isArrowPointingDown = toolbarHeightNeeded <= availableHeight;

            float arrowTipX = (position.dx + globalEditableRegion.left).clamp(
                CupertinoTextSelectionUtils._kArrowScreenPadding + mediaQuery.padding.left,
                mediaQuery.size.width - mediaQuery.padding.right - CupertinoTextSelectionUtils._kArrowScreenPadding
                );
            float localBarTopY = isArrowPointingDown
                  ? endpoints.first().point.dy - textLineHeight - CupertinoTextSelectionUtils._kToolbarContentDistance - CupertinoTextSelectionUtils._kToolbarHeight
                  : endpoints.last().point.dy + CupertinoTextSelectionUtils._kToolbarContentDistance;

            List <Widget> items = new List <Widget> {
            };
            Widget onePhysicalPixelVerticalDivider = new SizedBox(width: 1.0f / MediaQuery.of(context).devicePixelRatio);
            CupertinoLocalizations localizations   = CupertinoLocalizations.of(context);
            EdgeInsets             arrowPadding    = isArrowPointingDown
                  ? EdgeInsets.only(bottom: CupertinoTextSelectionUtils._kToolbarArrowSize.height)
                  : EdgeInsets.only(top: CupertinoTextSelectionUtils._kToolbarArrowSize.height);

            void addToolbarButtonIfNeeded(
                string text,
                Predicate predicate,
                OnPressed onPressed)
            {
                if (!predicate(_delegate))
                {
                    return;
                }

                if (items.isNotEmpty())
                {
                    items.Add(onePhysicalPixelVerticalDivider);
                }

                items.Add(new CupertinoButton(
                              child: new Text(text, style: CupertinoTextSelectionUtils._kToolbarButtonFontStyle),
                              color: CupertinoTextSelectionUtils._kToolbarBackgroundColor,
                              minSize: CupertinoTextSelectionUtils._kToolbarHeight,
                              padding: CupertinoTextSelectionUtils._kToolbarButtonPadding.add(arrowPadding),
                              borderRadius: null,
                              pressedOpacity: 0.7f,
                              onPressed: () => onPressed(_delegate)
                              ));
            }

            addToolbarButtonIfNeeded(localizations.cutButtonLabel, canCut, handleCut);
            addToolbarButtonIfNeeded(localizations.copyButtonLabel, canCopy, handleCopy);
            addToolbarButtonIfNeeded(localizations.pasteButtonLabel, canPaste, handlePaste);
            addToolbarButtonIfNeeded(localizations.selectAllButtonLabel, canSelectAll, handleSelectAll);
            return(new CupertinoTextSelectionToolbar(
                       barTopY: localBarTopY + globalEditableRegion.top,
                       arrowTipX: arrowTipX,
                       isArrowPointingDown: isArrowPointingDown,
                       child: items.isEmpty() ? null : new DecoratedBox(
                           decoration: new BoxDecoration(color: CupertinoTextSelectionUtils._kToolbarDividerColor),
                           child: new Row(mainAxisSize: MainAxisSize.min, children: items)
                           )
                       ));
        }
Exemple #9
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
                                   )
                               )
                           )
                       ));
        }
Exemple #10
0
        public override Widget build(BuildContext context)
        {
            base.build(context); // See AutomaticKeepAliveClientMixin.
            D.assert(MaterialD.debugCheckHasMaterial(context));
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            ThemeData                 themeData          = Theme.of(context);
            TextStyle                 style              = this.widget.style ?? themeData.textTheme.subhead;
            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));
            }


            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.enableInteractiveSelection
                        ? MaterialUtils.materialTextSelectionControls
                        : null,
                    onChanged: this.widget.onChanged,
                    onEditingComplete: this.widget.onEditingComplete,
                    onSubmitted: this.widget.onSubmitted,
                    onSelectionChanged: this._handleSelectionChanged,
                    inputFormatters: formatters,
                    rendererIgnoresPointer: true,
                    cursorWidth: this.widget.cursorWidth,
                    cursorRadius: this.widget.cursorRadius,
                    cursorColor: this.widget.cursorColor ?? Theme.of(context).cursorColor,
                    scrollPadding: this.widget.scrollPadding,
                    keyboardAppearance: keyboardAppearance,
                    enableInteractiveSelection: this.widget.enableInteractiveSelection
                    )
                );

            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,
                           onSingleTapUp: this._handleSingleTapUp,
                           onSingleTapCancel: this._handleSingleTapCancel,
                           onSingleLongTapStart: this._handleLongPress,
                           onDragSelectionStart: this._handleDragSelectionStart,
                           onDragSelectionUpdate: this._handleDragSelectionUpdate,
                           behavior: HitTestBehavior.translucent,
                           child: child
                           )
                       ));
        }