Exemplo n.º 1
0
        BorderRadius _getClipBorderRadius(
            int index,
            int length,
            TextDirection textDirection,
            ToggleButtonsThemeData toggleButtonsTheme
            )
        {
            BorderRadius resultingBorderRadius = borderRadius
                                                 ?? toggleButtonsTheme.borderRadius
                                                 ?? BorderRadius.zero;
            float resultingBorderWidth = borderWidth
                                         ?? toggleButtonsTheme.borderWidth
                                         ?? _defaultBorderWidth;

            if (_isFirstIndex(index, length, textDirection))
            {
                return(BorderRadius.only(
                           topLeft: resultingBorderRadius.topLeft - Radius.circular(resultingBorderWidth / 2.0f),
                           bottomLeft: resultingBorderRadius.bottomLeft - Radius.circular(resultingBorderWidth / 2.0f)
                           ));
            }
            else if (_isLastIndex(index, length, textDirection))
            {
                return(BorderRadius.only(
                           topRight: resultingBorderRadius.topRight - Radius.circular(resultingBorderWidth / 2.0f),
                           bottomRight: resultingBorderRadius.bottomRight - Radius.circular(resultingBorderWidth / 2.0f)
                           ));
            }

            return(BorderRadius.zero);
        }
Exemplo n.º 2
0
        BorderRadius _getEdgeBorderRadius(
            int index,
            int length,
            TextDirection textDirection,
            ToggleButtonsThemeData toggleButtonsTheme
            )
        {
            BorderRadius resultingBorderRadius = borderRadius
                                                 ?? toggleButtonsTheme.borderRadius
                                                 ?? BorderRadius.zero;

            if (_isFirstIndex(index, length, textDirection))
            {
                return(BorderRadius.only(
                           topLeft: resultingBorderRadius.topLeft,
                           bottomLeft: resultingBorderRadius.bottomLeft
                           ));
            }
            else if (_isLastIndex(index, length, textDirection))
            {
                return(BorderRadius.only(
                           topRight: resultingBorderRadius.topRight,
                           bottomRight: resultingBorderRadius.bottomRight
                           ));
            }

            return(BorderRadius.zero);
        }
Exemplo n.º 3
0
 public ToggleButtonsTheme(
     Key key = null,
     ToggleButtonsThemeData data = null,
     Widget child = null
     ) : base(key: key, child: child)
 {
     D.assert(data != null);
     this.data = data;
 }
Exemplo n.º 4
0
        BorderSide _getTrailingBorderSide(
            int index,
            ThemeData theme,
            ToggleButtonsThemeData toggleButtonsTheme
            )
        {
            if (!renderBorder)
            {
                return(BorderSide.none);
            }

            if (index != children.Count - 1)
            {
                return(null);
            }

            float resultingBorderWidth = borderWidth
                                         ?? toggleButtonsTheme.borderWidth
                                         ?? _defaultBorderWidth;

            if (onPressed != null && (isSelected[index]))
            {
                return(new BorderSide(
                           color: selectedBorderColor
                           ?? toggleButtonsTheme.selectedBorderColor
                           ?? theme.colorScheme.onSurface.withOpacity(0.12f),
                           width: resultingBorderWidth
                           ));
            }
            else if (onPressed != null && !isSelected[index])
            {
                return(new BorderSide(
                           color: borderColor
                           ?? toggleButtonsTheme.borderColor
                           ?? theme.colorScheme.onSurface.withOpacity(0.12f),
                           width: resultingBorderWidth
                           ));
            }
            else
            {
                return(new BorderSide(
                           color: disabledBorderColor
                           ?? toggleButtonsTheme.disabledBorderColor
                           ?? theme.colorScheme.onSurface.withOpacity(0.12f),
                           width: resultingBorderWidth
                           ));
            }
        }
Exemplo n.º 5
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterial(context));
            Color     currentColor       = null;
            Color     currentFillColor   = null;
            Color     currentFocusColor  = null;
            Color     currentHoverColor  = null;
            Color     currentSplashColor = null;
            ThemeData theme = Theme.of(context);
            ToggleButtonsThemeData toggleButtonsTheme = ToggleButtonsTheme.of(context);

            if (onPressed != null && selected)
            {
                currentColor = selectedColor
                               ?? toggleButtonsTheme.selectedColor
                               ?? theme.colorScheme.primary;
                currentFillColor = fillColor
                                   ?? theme.colorScheme.primary.withOpacity(0.12f);
                currentFocusColor = focusColor
                                    ?? toggleButtonsTheme.focusColor
                                    ?? theme.colorScheme.primary.withOpacity(0.12f);
                currentHoverColor = hoverColor
                                    ?? toggleButtonsTheme.hoverColor
                                    ?? theme.colorScheme.primary.withOpacity(0.04f);
                currentSplashColor = splashColor
                                     ?? toggleButtonsTheme.splashColor
                                     ?? theme.colorScheme.primary.withOpacity(0.16f);
            }
            else if (onPressed != null && !selected)
            {
                currentColor = color
                               ?? toggleButtonsTheme.color
                               ?? theme.colorScheme.onSurface.withOpacity(0.87f);
                currentFillColor  = theme.colorScheme.surface.withOpacity(0.0f);
                currentFocusColor = focusColor
                                    ?? toggleButtonsTheme.focusColor
                                    ?? theme.colorScheme.onSurface.withOpacity(0.12f);
                currentHoverColor = hoverColor
                                    ?? toggleButtonsTheme.hoverColor
                                    ?? theme.colorScheme.onSurface.withOpacity(0.04f);
                currentSplashColor = splashColor
                                     ?? toggleButtonsTheme.splashColor
                                     ?? theme.colorScheme.onSurface.withOpacity(0.16f);
            }
            else
            {
                currentColor = disabledColor
                               ?? toggleButtonsTheme.disabledColor
                               ?? theme.colorScheme.onSurface.withOpacity(0.38f);
                currentFillColor = theme.colorScheme.surface.withOpacity(0.0f);
            }

            TextStyle      currentTextStyle   = textStyle ?? toggleButtonsTheme.textStyle ?? theme.textTheme.bodyText2;
            BoxConstraints currentConstraints = constraints ?? toggleButtonsTheme.constraints ??
                                                new BoxConstraints(minWidth: material_.kMinInteractiveDimension,
                                                                   minHeight: material_.kMinInteractiveDimension);

            Widget result = new ClipRRect(
                borderRadius: clipRadius,
                child: new RawMaterialButton(
                    textStyle: currentTextStyle.copyWith(
                        color: currentColor
                        ),
                    constraints: currentConstraints,
                    elevation: 0.0f,
                    highlightElevation: 0.0f,
                    fillColor: currentFillColor,
                    focusColor: currentFocusColor,
                    highlightColor: highlightColor
                    ?? theme.colorScheme.surface.withOpacity(0.0f),
                    hoverColor: currentHoverColor,
                    splashColor: currentSplashColor,
                    focusNode: focusNode,
                    materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
                    onPressed: onPressed,
                    child: child
                    )
                );

            return(new _SelectToggleButton(
                       key: key,
                       leadingBorderSide: leadingBorderSide,
                       horizontalBorderSide: horizontalBorderSide,
                       trailingBorderSide: trailingBorderSide,
                       borderRadius: borderRadius,
                       isFirstButton: isFirstButton,
                       isLastButton: isLastButton,
                       child: result
                       ));
        }
Exemplo n.º 6
0
        public override Widget build(BuildContext context)
        {
            D.assert(
                !isSelected.Any((bool val) => val == null),
                () => "All elements of isSelected must be non-null.\n" +
                "The current list of isSelected values is as follows:\n" +
                $"{isSelected}"
                );
            D.assert(
                focusNodes == null || !focusNodes.Any((FocusNode val) => val == null),
                () => "All elements of focusNodes must be non-null.\n" +
                "The current list of focus node values is as follows:\n" +
                $"{focusNodes}"
                );
            D.assert(
                () => {
                if (focusNodes != null)
                {
                    return(focusNodes.Count == children.Count);
                }

                return(true);
            },
                () => "focusNodes.length must match children.length.\n" +
                $"There are {focusNodes.Count} focus nodes, while " +
                $"there are {children.Count} children."
                );

            ThemeData theme = Theme.of(context);
            ToggleButtonsThemeData toggleButtonsTheme = ToggleButtonsTheme.of(context);
            TextDirection          textDirection      = Directionality.of(context);

            var childrenList = new List <Widget>(children.Count);

            for (var i = 0; i < children.Count; i++)
            {
                var          index            = i;
                BorderRadius edgeBorderRadius =
                    _getEdgeBorderRadius(index, children.Count, textDirection, toggleButtonsTheme);
                BorderRadius clipBorderRadius =
                    _getClipBorderRadius(index, children.Count, textDirection, toggleButtonsTheme);

                BorderSide leadingBorderSide    = _getLeadingBorderSide(index, theme, toggleButtonsTheme);
                BorderSide horizontalBorderSide = _getHorizontalBorderSide(index, theme, toggleButtonsTheme);
                BorderSide trailingBorderSide   = _getTrailingBorderSide(index, theme, toggleButtonsTheme);

                childrenList.Add(new _ToggleButton(
                                     selected: isSelected[index],
                                     textStyle: textStyle,
                                     constraints: constraints,
                                     color: color,
                                     selectedColor: selectedColor,
                                     disabledColor: disabledColor,
                                     fillColor: fillColor ?? toggleButtonsTheme.fillColor,
                                     focusColor: focusColor ?? toggleButtonsTheme.focusColor,
                                     highlightColor: highlightColor ?? toggleButtonsTheme.highlightColor,
                                     hoverColor: hoverColor ?? toggleButtonsTheme.hoverColor,
                                     splashColor: splashColor ?? toggleButtonsTheme.splashColor,
                                     focusNode: focusNodes != null ? focusNodes[index] : null,
                                     onPressed: onPressed != null
                        ? () => { onPressed(index); }
                        : (VoidCallback)null,
                                     leadingBorderSide: leadingBorderSide,
                                     horizontalBorderSide: horizontalBorderSide,
                                     trailingBorderSide: trailingBorderSide,
                                     borderRadius: edgeBorderRadius,
                                     clipRadius: clipBorderRadius,
                                     isFirstButton: index == 0,
                                     isLastButton: index == children.Count - 1,
                                     child: children[index]
                                     ));
            }

            return(new IntrinsicHeight(
                       child: new Row(
                           crossAxisAlignment: CrossAxisAlignment.stretch,
                           mainAxisSize: MainAxisSize.min,
                           children: childrenList)
                       ));
        }