Beispiel #1
0
        TimeSpan getFadeDurationForType(_HighlightType type)
        {
            switch (type)
            {
            case _HighlightType.pressed:
                return(new TimeSpan(0, 0, 0, 0, 200));

            case _HighlightType.hover:
            case _HighlightType.focus:
                return(new TimeSpan(0, 0, 0, 0, 50));
            }

            D.assert(false, () => $"Unhandled {typeof(_HighlightType)} {type}");
            return(TimeSpan.Zero);
        }
Beispiel #2
0
        Color getHighlightColorForType(_HighlightType type)
        {
            switch (type)
            {
            case _HighlightType.pressed:
                return(widget.highlightColor ?? Theme.of(context).highlightColor);

            case _HighlightType.focus:
                return(widget.focusColor ?? Theme.of(context).focusColor);

            case _HighlightType.hover:
                return(widget.hoverColor ?? Theme.of(context).hoverColor);
            }

            D.assert(false, () => $"Unhandled {typeof(_HighlightType)} {type}");
            return(null);
        }
Beispiel #3
0
        public void updateHighlight(_HighlightType type, bool value)
        {
            InkHighlight highlight = _highlights.getOrDefault(type);

            void handleInkRemoval()
            {
                D.assert(_highlights.getOrDefault(type) != null);
                _highlights[type] = null;
                updateKeepAlive();
            }

            if (value == (highlight != null && highlight.active))
            {
                return;
            }

            if (value)
            {
                if (highlight == null)
                {
                    RenderBox referenceBox = (RenderBox)context.findRenderObject();
                    _highlights[type] = new InkHighlight(
                        controller: Material.of(context),
                        referenceBox: referenceBox,
                        color: getHighlightColorForType(type),
                        shape: widget.highlightShape,
                        borderRadius: widget.borderRadius,
                        customBorder: widget.customBorder,
                        rectCallback: widget.getRectCallback(referenceBox),
                        onRemoved: handleInkRemoval,
                        textDirection: Directionality.of(context),
                        fadeDuration: getFadeDurationForType(type)
                        );
                    updateKeepAlive();
                }
                else
                {
                    highlight.activate();
                }
            }
            else
            {
                highlight.deactivate();
            }

            D.assert(value == (_highlights.getOrDefault(type) != null && _highlights[type].active));
            switch (type)
            {
            case _HighlightType.pressed: {
                if (widget.onHighlightChanged != null)
                {
                    widget.onHighlightChanged(value);
                }
                break;
            }

            case _HighlightType.hover: {
                if (widget.onHover != null)
                {
                    widget.onHover(value);
                }
                break;
            }

            case _HighlightType.focus:
                break;
            }
        }