コード例 #1
0
ファイル: color_scheme.cs プロジェクト: zmtzawqlp/UIWidgets
        public static ColorScheme fromSwatch(
            MaterialColor primarySwatch = null,
            Color primaryColorDark      = null,
            Color accentColor           = null,
            Color cardColor             = null,
            Color backgroundColor       = null,
            Color errorColor            = null,
            Brightness?brightness       = Brightness.light)
        {
            D.assert(brightness != null);
            primarySwatch = primarySwatch ?? Colors.blue;

            bool  isDark          = brightness == Brightness.dark;
            bool  primaryIsDark   = _brightnessFor(primarySwatch) == Brightness.dark;
            Color secondary       = accentColor ?? (isDark ? Colors.tealAccent[200] : primarySwatch);
            bool  secondaryIsDark = _brightnessFor(secondary) == Brightness.dark;

            return(new ColorScheme(
                       primary: primarySwatch,
                       primaryVariant: primaryColorDark ?? (isDark ? Colors.black : primarySwatch[700]),
                       secondary: secondary,
                       secondaryVariant: isDark ? Colors.tealAccent[700] : primarySwatch[700],
                       surface: cardColor ?? (isDark ? Colors.grey[800] : Colors.white),
                       background: backgroundColor ?? (isDark ? Colors.grey[700] : primarySwatch[200]),
                       error: errorColor ?? Colors.red[700],
                       onPrimary: primaryIsDark ? Colors.white : Colors.black,
                       onSecondary: secondaryIsDark ? Colors.white : Colors.black,
                       onSurface: isDark ? Colors.white : Colors.black,
                       onBackground: primaryIsDark ? Colors.white : Colors.black,
                       onError: isDark ? Colors.black : Colors.white,
                       brightness: brightness ?? Brightness.light
                       ));
        }
コード例 #2
0
        public ThemeData(
            Brightness?brightness             = null,
            MaterialColor primarySwatch       = null,
            Color primaryColor                = null,
            Brightness?primaryColorBrightness = null,
            Color primaryColorLight           = null,
            Color primaryColorDark            = null,
            Color accentColor = null,
            Brightness?accentColorBrightness = null,
            Color canvasColor             = null,
            Color scaffoldBackgroundColor = null,
            Color bottomAppBarColor       = null,
            Color cardColor      = null,
            Color dividerColor   = null,
            Color highlightColor = null,
            Color splashColor    = null,
            InteractiveInkFeatureFactory splashFactory = null,
            Color selectedRowColor         = null,
            Color unselectedWidgetColor    = null,
            Color disabledColor            = null,
            Color buttonColor              = null,
            ButtonThemeData buttonTheme    = null,
            Color secondaryHeaderColor     = null,
            Color textSelectionColor       = null,
            Color cursorColor              = null,
            Color textSelectionHandleColor = null,
            Color backgroundColor          = null,
            Color dialogBackgroundColor    = null,
            Color indicatorColor           = null,
            Color hintColor                = null,
            Color errorColor               = null,
            Color toggleableActiveColor    = null,
            string fontFamily              = null,
            TextTheme textTheme            = null,
            TextTheme primaryTextTheme     = null,
            TextTheme accentTextTheme      = null,
            IconThemeData iconTheme        = null,
            IconThemeData primaryIconTheme = null,
            IconThemeData accentIconTheme  = null,
            MaterialTapTargetSize?materialTapTargetSize = null,
            PageTransitionsTheme pageTransitionsTheme   = null,
            ColorScheme colorScheme = null,
            Typography typography   = null
            )
        {
            brightness = brightness ?? Brightness.light;
            bool isDark = brightness == Brightness.dark;

            primarySwatch          = primarySwatch ?? Colors.blue;
            primaryColor           = primaryColor ?? (isDark ? Colors.grey[900] : primarySwatch);
            primaryColorBrightness = primaryColorBrightness ?? estimateBrightnessForColor(primaryColor);
            primaryColorLight      = primaryColorLight ?? (isDark ? Colors.grey[500] : primarySwatch[100]);
            primaryColorDark       = primaryColorDark ?? (isDark ? Colors.black : primarySwatch[700]);
            bool primaryIsDark = primaryColorBrightness == Brightness.dark;

            toggleableActiveColor = toggleableActiveColor ??
                                    (isDark ? Colors.tealAccent[200] : (accentColor ?? primarySwatch[600]));

            accentColor           = accentColor ?? (isDark ? Colors.tealAccent[200] : primarySwatch[500]);
            accentColorBrightness = accentColorBrightness ?? estimateBrightnessForColor(accentColor);
            bool accentIsDark = accentColorBrightness == Brightness.dark;

            canvasColor             = canvasColor ?? (isDark ? Colors.grey[850] : Colors.grey[50]);
            scaffoldBackgroundColor = scaffoldBackgroundColor ?? canvasColor;
            bottomAppBarColor       = bottomAppBarColor ?? (isDark ? Colors.grey[800] : Colors.white);
            cardColor    = cardColor ?? (isDark ? Colors.grey[800] : Colors.white);
            dividerColor = dividerColor ?? (isDark ? new Color(0x1FFFFFFF) : new Color(0x1F000000));

            colorScheme = colorScheme ?? ColorScheme.fromSwatch(
                primarySwatch: primarySwatch,
                primaryColorDark: primaryColorDark,
                accentColor: accentColor,
                cardColor: cardColor,
                backgroundColor: backgroundColor,
                errorColor: errorColor,
                brightness: brightness);

            splashFactory            = splashFactory ?? InkSplash.splashFactory;
            selectedRowColor         = selectedRowColor ?? Colors.grey[100];
            unselectedWidgetColor    = unselectedWidgetColor ?? (isDark ? Colors.white70 : Colors.black54);
            secondaryHeaderColor     = secondaryHeaderColor ?? (isDark ? Colors.grey[700] : primarySwatch[50]);
            textSelectionColor       = textSelectionColor ?? (isDark ? accentColor : primarySwatch[200]);
            cursorColor              = cursorColor ?? Color.fromRGBO(66, 133, 244, 1.0f);
            textSelectionHandleColor =
                textSelectionHandleColor ?? (isDark ? Colors.tealAccent[400] : primarySwatch[300]);

            backgroundColor       = backgroundColor ?? (isDark ? Colors.grey[700] : primarySwatch[200]);
            dialogBackgroundColor = dialogBackgroundColor ?? (isDark ? Colors.grey[800] : Colors.white);
            indicatorColor        = indicatorColor ?? (accentColor == primaryColor ? Colors.white : accentColor);
            hintColor             = hintColor ?? (isDark ? new Color(0x80FFFFFF) : new Color(0x8A000000));
            errorColor            = errorColor ?? Colors.red[700];

            pageTransitionsTheme = pageTransitionsTheme ?? new PageTransitionsTheme();
            primaryIconTheme     = primaryIconTheme ??
                                   (primaryIsDark
                                   ? new IconThemeData(color: Colors.white)
                                   : new IconThemeData(color: Colors.black));
            accentIconTheme = accentIconTheme ??
                              (accentIsDark
                                  ? new IconThemeData(color: Colors.white)
                                  : new IconThemeData(color: Colors.black));
            iconTheme = iconTheme ??
                        (isDark ? new IconThemeData(color: Colors.white) : new IconThemeData(color: Colors.black87));

            typography = typography ?? new Typography();
            TextTheme defaultTextTheme = isDark ? typography.white : typography.black;

            textTheme = defaultTextTheme.merge(textTheme);
            TextTheme defaultPrimaryTextTheme = primaryIsDark ? typography.white : typography.black;

            primaryTextTheme = defaultPrimaryTextTheme.merge(primaryTextTheme);
            TextTheme defaultAccentTextTheme = accentIsDark ? typography.white : typography.black;

            accentTextTheme       = defaultAccentTextTheme.merge(accentTextTheme);
            materialTapTargetSize = materialTapTargetSize ?? MaterialTapTargetSize.padded;
            if (fontFamily != null)
            {
                textTheme        = textTheme.apply(fontFamily: fontFamily);
                primaryTextTheme = primaryTextTheme.apply(fontFamily: fontFamily);
                accentTextTheme  = accentTextTheme.apply(fontFamily: fontFamily);
            }

            buttonColor = buttonColor ?? (isDark ? primarySwatch[600] : Colors.grey[300]);
            buttonTheme = buttonTheme ?? new ButtonThemeData(
                colorScheme: colorScheme,
                buttonColor: buttonColor,
                disabledColor: disabledColor,
                highlightColor: highlightColor,
                splashColor: splashColor,
                materialTapTargetSize: materialTapTargetSize);
            disabledColor  = disabledColor ?? (isDark ? Colors.white30 : Colors.black38);
            highlightColor = highlightColor ??
                             (isDark
                                 ? ThemeDataUtils._kDarkThemeHighlightColor
                                 : ThemeDataUtils._kLightThemeHighlightColor);
            splashColor = splashColor ??
                          (isDark
                              ? ThemeDataUtils._kDarkThemeSplashColor
                              : ThemeDataUtils._kLightThemeSplashColor);

            D.assert(brightness != null);
            D.assert(primaryColor != null);
            D.assert(primaryColorBrightness != null);
            D.assert(primaryColorLight != null);
            D.assert(primaryColorDark != null);
            D.assert(accentColor != null);
            D.assert(accentColorBrightness != null);
            D.assert(canvasColor != null);
            D.assert(scaffoldBackgroundColor != null);
            D.assert(bottomAppBarColor != null);
            D.assert(cardColor != null);
            D.assert(dividerColor != null);
            D.assert(highlightColor != null);
            D.assert(splashColor != null);
            D.assert(splashFactory != null);
            D.assert(selectedRowColor != null);
            D.assert(unselectedWidgetColor != null);
            D.assert(disabledColor != null);
            D.assert(toggleableActiveColor != null);
            D.assert(buttonTheme != null);
            D.assert(secondaryHeaderColor != null);
            D.assert(textSelectionColor != null);
            D.assert(cursorColor != null);
            D.assert(textSelectionHandleColor != null);
            D.assert(backgroundColor != null);
            D.assert(dialogBackgroundColor != null);
            D.assert(indicatorColor != null);
            D.assert(hintColor != null);
            D.assert(errorColor != null);
            D.assert(textTheme != null);
            D.assert(primaryTextTheme != null);
            D.assert(accentTextTheme != null);
            D.assert(iconTheme != null);
            D.assert(primaryIconTheme != null);
            D.assert(accentIconTheme != null);
            D.assert(materialTapTargetSize != null);
            D.assert(pageTransitionsTheme != null);
            D.assert(colorScheme != null);
            D.assert(typography != null);

            D.assert(buttonColor != null);

            this.brightness              = brightness ?? Brightness.light;
            this.primaryColor            = primaryColor;
            this.primaryColorBrightness  = primaryColorBrightness ?? Brightness.light;
            this.primaryColorLight       = primaryColorLight;
            this.primaryColorDark        = primaryColorDark;
            this.canvasColor             = canvasColor;
            this.accentColor             = accentColor;
            this.accentColorBrightness   = accentColorBrightness ?? Brightness.light;
            this.scaffoldBackgroundColor = scaffoldBackgroundColor;
            this.bottomAppBarColor       = bottomAppBarColor;
            this.cardColor                = cardColor;
            this.dividerColor             = dividerColor;
            this.highlightColor           = highlightColor;
            this.splashColor              = splashColor;
            this.splashFactory            = splashFactory;
            this.selectedRowColor         = selectedRowColor;
            this.unselectedWidgetColor    = unselectedWidgetColor;
            this.disabledColor            = disabledColor;
            this.buttonTheme              = buttonTheme;
            this.buttonColor              = buttonColor;
            this.secondaryHeaderColor     = secondaryHeaderColor;
            this.textSelectionColor       = textSelectionColor;
            this.cursorColor              = cursorColor;
            this.textSelectionHandleColor = textSelectionHandleColor;
            this.backgroundColor          = backgroundColor;
            this.dialogBackgroundColor    = dialogBackgroundColor;
            this.indicatorColor           = indicatorColor;
            this.hintColor                = hintColor;
            this.errorColor               = errorColor;
            this.toggleableActiveColor    = toggleableActiveColor;
            this.textTheme                = textTheme;
            this.primaryTextTheme         = primaryTextTheme;
            this.accentTextTheme          = accentTextTheme;
            this.iconTheme                = iconTheme;
            this.primaryIconTheme         = primaryIconTheme;
            this.accentIconTheme          = accentIconTheme;
            this.materialTapTargetSize    = materialTapTargetSize ?? MaterialTapTargetSize.padded;
            this.pageTransitionsTheme     = pageTransitionsTheme;
            this.colorScheme              = colorScheme;
            this.typography               = typography;
        }