Exemple #1
0
        public static ChipThemeData fromDefaults(
            Brightness?brightness = null,
            Color primaryColor    = null,
            Color secondaryColor  = null,
            TextStyle labelStyle  = null
            )
        {
            D.assert(primaryColor != null || brightness != null,
                     "One of primaryColor or brightness must be specified");
            D.assert(primaryColor == null || brightness == null,
                     "Only one of primaryColor or brightness may be specified");
            D.assert(secondaryColor != null);
            D.assert(labelStyle != null);

            if (primaryColor != null)
            {
                brightness = ThemeData.estimateBrightnessForColor(primaryColor);
            }

            const int   backgroundAlpha = 0x1f; // 12%
            const int   deleteIconAlpha = 0xde; // 87%
            const int   disabledAlpha   = 0x0c; // 38% * 12% = 5%
            const int   selectAlpha     = 0x3d; // 12% + 12% = 24%
            const int   textLabelAlpha  = 0xde; // 87%
            ShapeBorder shape           = new StadiumBorder();
            EdgeInsets  labelPadding    = EdgeInsets.symmetric(horizontal: 8.0f);
            EdgeInsets  padding         = EdgeInsets.all(4.0f);

            primaryColor = primaryColor ?? (brightness == Brightness.light ? Colors.black : Colors.white);
            Color     backgroundColor        = primaryColor.withAlpha(backgroundAlpha);
            Color     deleteIconColor        = primaryColor.withAlpha(deleteIconAlpha);
            Color     disabledColor          = primaryColor.withAlpha(disabledAlpha);
            Color     selectedColor          = primaryColor.withAlpha(selectAlpha);
            Color     secondarySelectedColor = secondaryColor.withAlpha(selectAlpha);
            TextStyle secondaryLabelStyle    = labelStyle.copyWith(
                color: secondaryColor.withAlpha(textLabelAlpha)
                );

            labelStyle = labelStyle.copyWith(color: primaryColor.withAlpha(textLabelAlpha));

            return(new ChipThemeData(
                       backgroundColor: backgroundColor,
                       deleteIconColor: deleteIconColor,
                       disabledColor: disabledColor,
                       selectedColor: selectedColor,
                       secondarySelectedColor: secondarySelectedColor,
                       labelPadding: labelPadding,
                       padding: padding,
                       shape: shape,
                       labelStyle: labelStyle,
                       secondaryLabelStyle: secondaryLabelStyle,
                       brightness: brightness
                       ));
        }
Exemple #2
0
        public Color getTextColor(MaterialButton button)
        {
            if (!button.enabled)
            {
                return(this.getDisabledTextColor(button));
            }

            if (button.textColor != null)
            {
                return(button.textColor);
            }

            switch (this.getTextTheme(button))
            {
            case ButtonTextTheme.normal:
                return(this.getBrightness(button) == Brightness.dark ? Colors.white : Colors.black87);

            case ButtonTextTheme.accent:
                return(this.colorScheme.secondary);

            case ButtonTextTheme.primary: {
                Color fillColor  = this.getFillColor(button);
                bool  fillIsDark = fillColor != null
                        ? ThemeData.estimateBrightnessForColor(fillColor) == Brightness.dark
                        : this.getBrightness(button) == Brightness.dark;

                if (fillIsDark)
                {
                    return(Colors.white);
                }

//todo:xingwei.zhu: uncomment these when OutlineButton are ready
                if (button is FlatButton /* || button is OutlineButton*/)
                {
                    return(this.colorScheme.primary);
                }

                return(Colors.black);
            }
            }

            D.assert(false);
            return(null);
        }
Exemple #3
0
        public Color getTextColor(MaterialButton button)
        {
            if (!button.enabled)
            {
                return(getDisabledTextColor(button));
            }

            if (button.textColor != null)
            {
                return(button.textColor);
            }

            switch (getTextTheme(button))
            {
            case ButtonTextTheme.normal:
                return(getBrightness(button) == Brightness.dark ? Colors.white : Colors.black87);

            case ButtonTextTheme.accent:
                return(colorScheme.secondary);

            case ButtonTextTheme.primary: {
                Color fillColor  = getFillColor(button);
                bool  fillIsDark = fillColor != null
                        ? ThemeData.estimateBrightnessForColor(fillColor) == Brightness.dark
                        : getBrightness(button) == Brightness.dark;

                if (fillIsDark)
                {
                    return(Colors.white);
                }

                if (button is FlatButton || button is OutlineButton)
                {
                    return(colorScheme.primary);
                }

                return(Colors.black);
            }
            }

            D.assert(false);
            return(null);
        }
Exemple #4
0
 static Brightness _brightnessFor(Color color)
 {
     return(ThemeData.estimateBrightnessForColor(color));
 }