From 031e042eeeadd518dda4425bd4827f5655ef4fcb Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Fri, 17 Mar 2017 15:24:54 -0700 Subject: [PATCH] Now each Colors.foo constant is-a Color and a color swatch (#8833) --- dev/manual_tests/card_collection.dart | 8 +- .../flutter_gallery/lib/demo/colors_demo.dart | 84 +- .../lib/demo/material/icons_demo.dart | 8 +- .../lib/demo/material/tabs_fab_demo.dart | 2 +- .../flutter_gallery/lib/gallery/drawer.dart | 37 +- examples/layers/widgets/gestures.dart | 62 +- packages/flutter/lib/src/material/colors.dart | 952 +++++++++++------- .../lib/src/material/flutter_logo.dart | 20 +- .../flutter/lib/src/material/list_tile.dart | 2 +- .../flutter/lib/src/material/theme_data.dart | 2 +- .../lib/src/painting/flutter_logo.dart | 84 +- .../flutter/test/material/colors_test.dart | 86 ++ 12 files changed, 832 insertions(+), 515 deletions(-) create mode 100644 packages/flutter/test/material/colors_test.dart diff --git a/dev/manual_tests/card_collection.dart b/dev/manual_tests/card_collection.dart index 0bfca126d9..1e2c261047 100644 --- a/dev/manual_tests/card_collection.dart +++ b/dev/manual_tests/card_collection.dart @@ -32,7 +32,7 @@ class CardCollectionState extends State { static const double kCardMargins = 8.0; static const double kFixedCardHeight = 100.0; - Map _primaryColor = Colors.deepPurple; + MaterialColor _primaryColor = Colors.deepPurple; List _cardModels; DismissDirection _dismissDirection = DismissDirection.horizontal; TextAlign _textAlign = TextAlign.center; @@ -148,7 +148,7 @@ class CardCollectionState extends State { }); } - void _selectColor(Map selection) { + void _selectColor(MaterialColor selection) { setState(() { _primaryColor = selection; }); @@ -181,14 +181,14 @@ class CardCollectionState extends State { ); } - Widget buildDrawerColorRadioItem(String label, Map itemValue, Map currentValue, ValueChanged> onChanged, { IconData icon, bool enabled: true }) { + Widget buildDrawerColorRadioItem(String label, MaterialColor itemValue, MaterialColor currentValue, ValueChanged onChanged, { IconData icon, bool enabled: true }) { return new DrawerItem( icon: new Icon(icon), onPressed: enabled ? () { onChanged(itemValue); } : null, child: new Row( children: [ new Expanded(child: new Text(label)), - new Radio>( + new Radio( value: itemValue, groupValue: currentValue, onChanged: enabled ? onChanged : null, diff --git a/examples/flutter_gallery/lib/demo/colors_demo.dart b/examples/flutter_gallery/lib/demo/colors_demo.dart index f28b08c6e5..dc7c7ff310 100644 --- a/examples/flutter_gallery/lib/demo/colors_demo.dart +++ b/examples/flutter_gallery/lib/demo/colors_demo.dart @@ -6,37 +6,37 @@ import 'package:flutter/material.dart'; const double kColorItemHeight = 48.0; -class ColorSwatch { - ColorSwatch({ this.name, this.colors, this.accentColors, this.threshold: 900}); +class Palette { + Palette({ this.name, this.primary, this.accent, this.threshold: 900}); final String name; - final Map colors; - final Map accentColors; + final MaterialColor primary; + final MaterialAccentColor accent; final int threshold; // titles for indices > threshold are white, otherwise black - bool get isValid => name != null && colors != null && threshold != null; + bool get isValid => name != null && primary != null && threshold != null; } -final List colorSwatches = [ - new ColorSwatch(name: 'RED', colors: Colors.red, accentColors: Colors.redAccent, threshold: 300), - new ColorSwatch(name: 'PINK', colors: Colors.pink, accentColors: Colors.pinkAccent, threshold: 200), - new ColorSwatch(name: 'PURPLE', colors: Colors.purple, accentColors: Colors.purpleAccent, threshold: 200), - new ColorSwatch(name: 'DEEP PURPLE', colors: Colors.deepPurple, accentColors: Colors.deepPurpleAccent, threshold: 200), - new ColorSwatch(name: 'INDIGO', colors: Colors.indigo, accentColors: Colors.indigoAccent, threshold: 200), - new ColorSwatch(name: 'BLUE', colors: Colors.blue, accentColors: Colors.blueAccent, threshold: 400), - new ColorSwatch(name: 'LIGHT BLUE', colors: Colors.lightBlue, accentColors: Colors.lightBlueAccent, threshold: 500), - new ColorSwatch(name: 'CYAN', colors: Colors.cyan, accentColors: Colors.cyanAccent, threshold: 600), - new ColorSwatch(name: 'TEAL', colors: Colors.teal, accentColors: Colors.tealAccent, threshold: 400), - new ColorSwatch(name: 'GREEN', colors: Colors.green, accentColors: Colors.greenAccent, threshold: 500), - new ColorSwatch(name: 'LIGHT GREEN', colors: Colors.lightGreen, accentColors: Colors.lightGreenAccent, threshold: 600), - new ColorSwatch(name: 'LIME', colors: Colors.lime, accentColors: Colors.limeAccent, threshold: 800), - new ColorSwatch(name: 'YELLOW', colors: Colors.yellow, accentColors: Colors.yellowAccent), - new ColorSwatch(name: 'AMBER', colors: Colors.amber, accentColors: Colors.amberAccent), - new ColorSwatch(name: 'ORANGE', colors: Colors.orange, accentColors: Colors.orangeAccent, threshold: 700), - new ColorSwatch(name: 'DEEP ORANGE', colors: Colors.deepOrange, accentColors: Colors.deepOrangeAccent, threshold: 400), - new ColorSwatch(name: 'BROWN', colors: Colors.brown, threshold: 200), - new ColorSwatch(name: 'GREY', colors: Colors.grey, threshold: 500), - new ColorSwatch(name: 'BLUE GREY', colors: Colors.blueGrey, threshold: 500), +final List allPalettes = [ + new Palette(name: 'RED', primary: Colors.red, accent: Colors.redAccent, threshold: 300), + new Palette(name: 'PINK', primary: Colors.pink, accent: Colors.pinkAccent, threshold: 200), + new Palette(name: 'PURPLE', primary: Colors.purple, accent: Colors.purpleAccent, threshold: 200), + new Palette(name: 'DEEP PURPLE', primary: Colors.deepPurple, accent: Colors.deepPurpleAccent, threshold: 200), + new Palette(name: 'INDIGO', primary: Colors.indigo, accent: Colors.indigoAccent, threshold: 200), + new Palette(name: 'BLUE', primary: Colors.blue, accent: Colors.blueAccent, threshold: 400), + new Palette(name: 'LIGHT BLUE', primary: Colors.lightBlue, accent: Colors.lightBlueAccent, threshold: 500), + new Palette(name: 'CYAN', primary: Colors.cyan, accent: Colors.cyanAccent, threshold: 600), + new Palette(name: 'TEAL', primary: Colors.teal, accent: Colors.tealAccent, threshold: 400), + new Palette(name: 'GREEN', primary: Colors.green, accent: Colors.greenAccent, threshold: 500), + new Palette(name: 'LIGHT GREEN', primary: Colors.lightGreen, accent: Colors.lightGreenAccent, threshold: 600), + new Palette(name: 'LIME', primary: Colors.lime, accent: Colors.limeAccent, threshold: 800), + new Palette(name: 'YELLOW', primary: Colors.yellow, accent: Colors.yellowAccent), + new Palette(name: 'AMBER', primary: Colors.amber, accent: Colors.amberAccent), + new Palette(name: 'ORANGE', primary: Colors.orange, accent: Colors.orangeAccent, threshold: 700), + new Palette(name: 'DEEP ORANGE', primary: Colors.deepOrange, accent: Colors.deepOrangeAccent, threshold: 400), + new Palette(name: 'BROWN', primary: Colors.brown, threshold: 200), + new Palette(name: 'GREY', primary: Colors.grey, threshold: 500), + new Palette(name: 'BLUE GREY', primary: Colors.blueGrey, threshold: 500), ]; @@ -71,29 +71,33 @@ class ColorItem extends StatelessWidget { } } -class ColorSwatchTabView extends StatelessWidget { - ColorSwatchTabView({ Key key, this.swatch }) : super(key: key) { - assert(swatch != null && swatch.isValid); +class PaletteTabView extends StatelessWidget { + static const List primaryKeys = const [50, 100, 200, 300, 400, 500, 600, 700, 800, 900]; + static const List accentKeys = const [100, 200, 400, 700]; + + PaletteTabView({ Key key, this.colors }) : super(key: key) { + assert(colors != null && colors.isValid); } - final ColorSwatch swatch; + final Palette colors; + @override Widget build(BuildContext context) { final TextTheme textTheme = Theme.of(context).textTheme; final TextStyle whiteTextStyle = textTheme.body1.copyWith(color: Colors.white); final TextStyle blackTextStyle = textTheme.body1.copyWith(color: Colors.black); - final List colorItems = swatch.colors.keys.map((int index) { + final List colorItems = primaryKeys.map((int index) { return new DefaultTextStyle( - style: index > swatch.threshold ? whiteTextStyle : blackTextStyle, - child: new ColorItem(index: index, color: swatch.colors[index]), + style: index > colors.threshold ? whiteTextStyle : blackTextStyle, + child: new ColorItem(index: index, color: colors.primary[index]), ); }).toList(); - if (swatch.accentColors != null) { - colorItems.addAll(swatch.accentColors.keys.map((int index) { + if (colors.accent != null) { + colorItems.addAll(accentKeys.map((int index) { return new DefaultTextStyle( - style: index > swatch.threshold ? whiteTextStyle : blackTextStyle, - child: new ColorItem(index: index, color: swatch.accentColors[index], prefix: 'A'), + style: index > colors.threshold ? whiteTextStyle : blackTextStyle, + child: new ColorItem(index: index, color: colors.accent[index], prefix: 'A'), ); }).toList()); } @@ -111,19 +115,19 @@ class ColorsDemo extends StatelessWidget { @override Widget build(BuildContext context) { return new DefaultTabController( - length: colorSwatches.length, + length: allPalettes.length, child: new Scaffold( appBar: new AppBar( elevation: 0, title: new Text('Colors'), bottom: new TabBar( isScrollable: true, - tabs: colorSwatches.map((ColorSwatch swatch) => new Tab(text: swatch.name)).toList(), + tabs: allPalettes.map((Palette swatch) => new Tab(text: swatch.name)).toList(), ), ), body: new TabBarView( - children: colorSwatches.map((ColorSwatch swatch) { - return new ColorSwatchTabView(swatch: swatch); + children: allPalettes.map((Palette colors) { + return new PaletteTabView(colors: colors); }).toList(), ), ), diff --git a/examples/flutter_gallery/lib/demo/material/icons_demo.dart b/examples/flutter_gallery/lib/demo/material/icons_demo.dart index d223ced25f..57f2cabdc9 100644 --- a/examples/flutter_gallery/lib/demo/material/icons_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/icons_demo.dart @@ -12,7 +12,7 @@ class IconsDemo extends StatefulWidget { } class IconsDemoState extends State { - static final List> iconColorSwatches = >[ + static final List iconColors = [ Colors.red, Colors.pink, Colors.purple, @@ -31,17 +31,17 @@ class IconsDemoState extends State { Colors.deepOrange, Colors.brown, Colors.grey, - Colors.blueGrey + Colors.blueGrey, ]; int iconColorIndex = 8; // teal double iconOpacity = 1.0; - Color get iconColor => iconColorSwatches[iconColorIndex][400]; + Color get iconColor => iconColors[iconColorIndex]; void handleIconButtonPress() { setState(() { - iconColorIndex = (iconColorIndex + 1) % iconColorSwatches.length; + iconColorIndex = (iconColorIndex + 1) % iconColors.length; }); } diff --git a/examples/flutter_gallery/lib/demo/material/tabs_fab_demo.dart b/examples/flutter_gallery/lib/demo/material/tabs_fab_demo.dart index 168479b300..bdedc71086 100644 --- a/examples/flutter_gallery/lib/demo/material/tabs_fab_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/tabs_fab_demo.dart @@ -14,7 +14,7 @@ class _Page { _Page({ this.label, this.colors, this.icon }); final String label; - final Map colors; + final MaterialColor colors; final IconData icon; Color get labelColor => colors != null ? colors[300] : Colors.grey[300]; diff --git a/examples/flutter_gallery/lib/gallery/drawer.dart b/examples/flutter_gallery/lib/gallery/drawer.dart index 4babb8eefa..e07025d4f3 100644 --- a/examples/flutter_gallery/lib/gallery/drawer.dart +++ b/examples/flutter_gallery/lib/gallery/drawer.dart @@ -31,7 +31,7 @@ class GalleryDrawerHeader extends StatefulWidget { class _GalleryDrawerHeaderState extends State { bool _logoHasName = true; bool _logoHorizontal = true; - Map _swatch = Colors.blue; + MaterialColor _logoColor = Colors.blue; @override Widget build(BuildContext context) { @@ -43,7 +43,8 @@ class _GalleryDrawerHeaderState extends State { style: _logoHasName ? _logoHorizontal ? FlutterLogoStyle.horizontal : FlutterLogoStyle.stacked : FlutterLogoStyle.markOnly, - swatch: _swatch, + lightColor: _logoColor.shade400, + darkColor: _logoColor.shade900, textColor: config.light ? const Color(0xFF616161) : const Color(0xFF9E9E9E), ), duration: const Duration(milliseconds: 750), @@ -62,22 +63,22 @@ class _GalleryDrawerHeaderState extends State { }, onDoubleTap: () { setState(() { - final List> options = >[]; - if (_swatch != Colors.blue) - options.addAll(>[Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue]); - if (_swatch != Colors.amber) - options.addAll(>[Colors.amber, Colors.amber, Colors.amber]); - if (_swatch != Colors.red) - options.addAll(>[Colors.red, Colors.red, Colors.red]); - if (_swatch != Colors.indigo) - options.addAll(>[Colors.indigo, Colors.indigo, Colors.indigo]); - if (_swatch != Colors.pink) - options.addAll(>[Colors.pink]); - if (_swatch != Colors.purple) - options.addAll(>[Colors.purple]); - if (_swatch != Colors.cyan) - options.addAll(>[Colors.cyan]); - _swatch = options[new math.Random().nextInt(options.length)]; + final List options = []; + if (_logoColor != Colors.blue) + options.addAll([Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue, Colors.blue]); + if (_logoColor != Colors.amber) + options.addAll([Colors.amber, Colors.amber, Colors.amber]); + if (_logoColor != Colors.red) + options.addAll([Colors.red, Colors.red, Colors.red]); + if (_logoColor != Colors.indigo) + options.addAll([Colors.indigo, Colors.indigo, Colors.indigo]); + if (_logoColor != Colors.pink) + options.addAll([Colors.pink]); + if (_logoColor != Colors.purple) + options.addAll([Colors.purple]); + if (_logoColor != Colors.cyan) + options.addAll([Colors.cyan]); + _logoColor = options[new math.Random().nextInt(options.length)]; }); } ) diff --git a/examples/layers/widgets/gestures.dart b/examples/layers/widgets/gestures.dart index a54a75287c..5c3be8a7b9 100644 --- a/examples/layers/widgets/gestures.dart +++ b/examples/layers/widgets/gestures.dart @@ -18,7 +18,7 @@ class _GesturePainter extends CustomPainter { final double zoom; final Offset offset; - final Map swatch; + final MaterialColor swatch; final bool forward; final bool scaleEnabled; final bool tapEnabled; @@ -71,7 +71,7 @@ class _GestureDemoState extends State { double _previousZoom; double _zoom = 1.0; - Map _swatch = Colors.blue; + MaterialColor _swatch = Colors.blue; bool _forward = true; bool _scaleEnabled = true; @@ -106,28 +106,42 @@ class _GestureDemoState extends State { void _handleColorChange() { setState(() { - switch (_swatch) { - case Colors.blueGrey: _swatch = Colors.red; break; - case Colors.red: _swatch = Colors.pink; break; - case Colors.pink: _swatch = Colors.purple; break; - case Colors.purple: _swatch = Colors.deepPurple; break; - case Colors.deepPurple: _swatch = Colors.indigo; break; - case Colors.indigo: _swatch = Colors.blue; break; - case Colors.blue: _swatch = Colors.lightBlue; break; - case Colors.lightBlue: _swatch = Colors.cyan; break; - case Colors.cyan: _swatch = Colors.teal; break; - case Colors.teal: _swatch = Colors.green; break; - case Colors.green: _swatch = Colors.lightGreen; break; - case Colors.lightGreen: _swatch = Colors.lime; break; - case Colors.lime: _swatch = Colors.yellow; break; - case Colors.yellow: _swatch = Colors.amber; break; - case Colors.amber: _swatch = Colors.orange; break; - case Colors.orange: _swatch = Colors.deepOrange; break; - case Colors.deepOrange: _swatch = Colors.brown; break; - case Colors.brown: _swatch = Colors.grey; break; - case Colors.grey: _swatch = Colors.blueGrey; break; - default: assert(false); - } + if (_swatch == Colors.blueGrey) + _swatch = Colors.red; + else if (_swatch == Colors.red) + _swatch = Colors.pink; + else if (_swatch == Colors.pink) + _swatch = Colors.purple; + else if (_swatch == Colors.purple) + _swatch = Colors.deepPurple; + else if (_swatch == Colors.deepPurple) + _swatch = Colors.indigo; + else if (_swatch == Colors.indigo) + _swatch = Colors.blue; + else if (_swatch == Colors.blue) + _swatch = Colors.lightBlue; + else if (_swatch == Colors.lightBlue) + _swatch = Colors.cyan; + else if (_swatch == Colors.teal) + _swatch = Colors.green; + else if (_swatch == Colors.green) + _swatch = Colors.lightGreen; + else if (_swatch == Colors.lightGreen) + _swatch = Colors.lime; + else if (_swatch == Colors.lime) + _swatch = Colors.yellow; + else if (_swatch == Colors.yellow) + _swatch = Colors.amber; + else if (_swatch == Colors.amber) + _swatch = Colors.orange; + else if (_swatch == Colors.orange) + _swatch = Colors.deepOrange; + else if (_swatch == Colors.deepOrange) + _swatch = Colors.brown; + else if (_swatch == Colors.brown) + _swatch = Colors.grey; + else if (_swatch == Colors.grey) + _swatch = Colors.blueGrey; }); } diff --git a/packages/flutter/lib/src/material/colors.dart b/packages/flutter/lib/src/material/colors.dart index 4c166cda80..9675032374 100644 --- a/packages/flutter/lib/src/material/colors.dart +++ b/packages/flutter/lib/src/material/colors.dart @@ -2,9 +2,85 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:ui' show Color; +import 'dart:ui' show Color, hashValues; -/// [Color] constants which represent Material design's +/// A color that has a small table of related colors called a "swatch". +/// +/// See also: +/// +/// * [MaterialColor] and [MaterialAccentColor], which define material design +/// primary and accent color swatches. +/// * [Colors], which defines all of the standard material design colors. +class ColorSwatch extends Color { + // Creates a color that has a small table of related colors called a "swatch". + const ColorSwatch(int primary, this._swatch) : super(primary); + + final Map _swatch; + + /// Returns an element of the [swatch] table. + Color operator [](int index) => _swatch[index]; + + @override + bool operator ==(dynamic other) { + if (identical(this, other)) + return true; + if (other.runtimeType != runtimeType) + return false; + final ColorSwatch typedOther = other; + return super==(other) && _swatch == typedOther._swatch; + } + + @override + int get hashCode => hashValues(runtimeType, value, _swatch); + + @override + String toString() => '$runtimeType(primary value: ${super.toString()})'; + +} + +/// Defines a single color as well a color swatch with ten shades of the color. +/// +/// The color's shades are referred to by index. The greater the index, the +/// darker the color. There are 10 valid indices: 50, 100, 200, ..., 900. +/// The value of this color should the same the value of index 500 and [shade500]. +/// +/// See also: +/// +/// * [Colors], which defines all of the standard material colors. +class MaterialColor extends ColorSwatch { + const MaterialColor(int primary, Map swatch) : super(primary, swatch); + Color get shade50 => _swatch[50]; + Color get shade100 => _swatch[100]; + Color get shade200 => _swatch[200]; + Color get shade300 => _swatch[300]; + Color get shade400 => _swatch[400]; + Color get shade500 => _swatch[500]; + Color get shade600 => _swatch[600]; + Color get shade700 => _swatch[700]; + Color get shade800 => _swatch[800]; + Color get shade900 => _swatch[900]; +} + +/// Defines a single accent color as well a swatch of four shades of the +/// accent color. +/// +/// The color's shades are referred to by index, the colors with smaller +/// indices are lighter, larger indices are darker. There are four valid +/// indices: 100, 200, 400, and 700. The value of this color should be the +/// same as the value of index 200 and [shade200]. +/// +/// See also: +/// +/// * [Colors], which defines all of the standard material colors. +class MaterialAccentColor extends ColorSwatch { + const MaterialAccentColor(int primary, Map swatch) : super(primary, swatch); + Color get shade100 => _swatch[100]; + Color get shade200 => _swatch[200]; + Color get shade400 => _swatch[400]; + Color get shade700 => _swatch[700]; +} + +/// [Color] and [ColorSwatch] constants which represent Material design's /// [color palette](http://material.google.com/style/color.html). /// /// Instead of using an absolute color from these palettes, consider using @@ -19,6 +95,14 @@ import 'dart:ui' show Color; /// Colors.green[400] // Selects a mid-range green. /// ``` /// +/// Each ColorSwatch constant is a color and can used directly. For example +/// +/// ```dart +/// new Container( +/// color: Colors.blue, // same as Colors.blue[500] or Colors.blue.shade500 +/// ) +/// ``` +/// /// Most swatches have colors from 100 to 900 in increments of one hundred, plus /// the color 50. The smaller the number, the more pale the color. The greater /// the number, the darker the color. The accent swatches (e.g. [redAccent]) only @@ -128,7 +212,7 @@ class Colors { static const Color white10 = const Color(0x1AFFFFFF); - /// The red primary swatch. + /// The red primary color and swatch. /// /// ```dart /// new Icon( @@ -142,18 +226,22 @@ class Colors { /// * [redAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map red = const { - 50: const Color(0xFFFFEBEE), - 100: const Color(0xFFFFCDD2), - 200: const Color(0xFFEF9A9A), - 300: const Color(0xFFE57373), - 400: const Color(0xFFEF5350), - 500: const Color(0xFFF44336), - 600: const Color(0xFFE53935), - 700: const Color(0xFFD32F2F), - 800: const Color(0xFFC62828), - 900: const Color(0xFFB71C1C), - }; + static const int _redPrimaryValue = 0xFFF44336; + static const MaterialColor red = const MaterialColor( + _redPrimaryValue, + const { + 50: const Color(0xFFFFEBEE), + 100: const Color(0xFFFFCDD2), + 200: const Color(0xFFEF9A9A), + 300: const Color(0xFFE57373), + 400: const Color(0xFFEF5350), + 500: const Color(_redPrimaryValue), + 600: const Color(0xFFE53935), + 700: const Color(0xFFD32F2F), + 800: const Color(0xFFC62828), + 900: const Color(0xFFB71C1C), + }, + ); /// The red accent swatch. /// @@ -169,14 +257,18 @@ class Colors { /// * [red], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map redAccent = const { - 100: const Color(0xFFFF8A80), - 200: const Color(0xFFFF5252), - 400: const Color(0xFFFF1744), - 700: const Color(0xFFD50000), - }; + static const int _redAccentValue = 0xFFFF5252; + static const MaterialAccentColor redAccent = const MaterialAccentColor( + _redAccentValue, + const { + 100: const Color(0xFFFF8A80), + 200: const Color(_redAccentValue), + 400: const Color(0xFFFF1744), + 700: const Color(0xFFD50000), + }, + ); - /// The pink primary swatch. + /// The pink primary color and swatch. /// /// ```dart /// new Icon( @@ -190,20 +282,24 @@ class Colors { /// * [pinkAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map pink = const { - 50: const Color(0xFFFCE4EC), - 100: const Color(0xFFF8BBD0), - 200: const Color(0xFFF48FB1), - 300: const Color(0xFFF06292), - 400: const Color(0xFFEC407A), - 500: const Color(0xFFE91E63), - 600: const Color(0xFFD81B60), - 700: const Color(0xFFC2185B), - 800: const Color(0xFFAD1457), - 900: const Color(0xFF880E4F), - }; + static const int _pinkPrimaryValue = 0xFFE91E63; + static const MaterialColor pink = const MaterialColor( + _pinkPrimaryValue, + const { + 50: const Color(0xFFFCE4EC), + 100: const Color(0xFFF8BBD0), + 200: const Color(0xFFF48FB1), + 300: const Color(0xFFF06292), + 400: const Color(0xFFEC407A), + 500: const Color(_pinkPrimaryValue), + 600: const Color(0xFFD81B60), + 700: const Color(0xFFC2185B), + 800: const Color(0xFFAD1457), + 900: const Color(0xFF880E4F), + }, + ); - /// The pink accent swatch. + /// The pink accent color swatch. /// /// ```dart /// new Icon( @@ -217,14 +313,18 @@ class Colors { /// * [pink], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map pinkAccent = const { - 100: const Color(0xFFFF80AB), - 200: const Color(0xFFFF4081), - 400: const Color(0xFFF50057), - 700: const Color(0xFFC51162), - }; + static const int _pinkAccentPrimaryValue = 0xFFFF4081; + static const MaterialAccentColor pinkAccent = const MaterialAccentColor( + _pinkAccentPrimaryValue, + const { + 100: const Color(0xFFFF80AB), + 200: const Color(_pinkAccentPrimaryValue), + 400: const Color(0xFFF50057), + 700: const Color(0xFFC51162), + }, + ); - /// The purple primary swatch. + /// The purple primary color and swatch. /// /// ```dart /// new Icon( @@ -238,20 +338,24 @@ class Colors { /// * [purpleAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map purple = const { - 50: const Color(0xFFF3E5F5), - 100: const Color(0xFFE1BEE7), - 200: const Color(0xFFCE93D8), - 300: const Color(0xFFBA68C8), - 400: const Color(0xFFAB47BC), - 500: const Color(0xFF9C27B0), - 600: const Color(0xFF8E24AA), - 700: const Color(0xFF7B1FA2), - 800: const Color(0xFF6A1B9A), - 900: const Color(0xFF4A148C), - }; + static const int _purplePrimaryValue = 0xFF9C27B0; + static const MaterialColor purple = const MaterialColor( + _purplePrimaryValue, + const { + 50: const Color(0xFFF3E5F5), + 100: const Color(0xFFE1BEE7), + 200: const Color(0xFFCE93D8), + 300: const Color(0xFFBA68C8), + 400: const Color(0xFFAB47BC), + 500: const Color(_purplePrimaryValue), + 600: const Color(0xFF8E24AA), + 700: const Color(0xFF7B1FA2), + 800: const Color(0xFF6A1B9A), + 900: const Color(0xFF4A148C), + }, + ); - /// The purple accent swatch. + /// The purple accent color and swatch. /// /// ```dart /// new Icon( @@ -265,14 +369,18 @@ class Colors { /// * [purple], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map purpleAccent = const { - 100: const Color(0xFFEA80FC), - 200: const Color(0xFFE040FB), - 400: const Color(0xFFD500F9), - 700: const Color(0xFFAA00FF), - }; + static const int _purpleAccentPrimaryValue = 0xFFE040FB; + static const MaterialAccentColor purpleAccent = const MaterialAccentColor( + _purpleAccentPrimaryValue, + const { + 100: const Color(0xFFEA80FC), + 200: const Color(_purpleAccentPrimaryValue), + 400: const Color(0xFFD500F9), + 700: const Color(0xFFAA00FF), + }, + ); - /// The deep purple primary swatch. + /// The deep purple primary color and swatch. /// /// ```dart /// new Icon( @@ -286,20 +394,24 @@ class Colors { /// * [deepPurpleAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map deepPurple = const { - 50: const Color(0xFFEDE7F6), - 100: const Color(0xFFD1C4E9), - 200: const Color(0xFFB39DDB), - 300: const Color(0xFF9575CD), - 400: const Color(0xFF7E57C2), - 500: const Color(0xFF673AB7), - 600: const Color(0xFF5E35B1), - 700: const Color(0xFF512DA8), - 800: const Color(0xFF4527A0), - 900: const Color(0xFF311B92), - }; + static const int _deepPurplePrimaryValue = 0xFF673AB7; + static const MaterialColor deepPurple = const MaterialColor( + _deepPurplePrimaryValue, + const { + 50: const Color(0xFFEDE7F6), + 100: const Color(0xFFD1C4E9), + 200: const Color(0xFFB39DDB), + 300: const Color(0xFF9575CD), + 400: const Color(0xFF7E57C2), + 500: const Color(_deepPurplePrimaryValue), + 600: const Color(0xFF5E35B1), + 700: const Color(0xFF512DA8), + 800: const Color(0xFF4527A0), + 900: const Color(0xFF311B92), + }, + ); - /// The deep purple accent swatch. + /// The deep purple accent color and swatch. /// /// ```dart /// new Icon( @@ -313,14 +425,18 @@ class Colors { /// * [deepPurple], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map deepPurpleAccent = const { - 100: const Color(0xFFB388FF), - 200: const Color(0xFF7C4DFF), - 400: const Color(0xFF651FFF), - 700: const Color(0xFF6200EA), - }; + static const int _deepPurpleAccentPrimaryValue = 0xFF7C4DFF; + static const MaterialAccentColor deepPurpleAccent = const MaterialAccentColor( + _deepPurpleAccentPrimaryValue, + const { + 100: const Color(0xFFB388FF), + 200: const Color(_deepPurpleAccentPrimaryValue), + 400: const Color(0xFF651FFF), + 700: const Color(0xFF6200EA), + }, + ); - /// The indigo primary swatch. + /// The indigo primary color and swatch. /// /// ```dart /// new Icon( @@ -334,20 +450,24 @@ class Colors { /// * [indigoAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map indigo = const { - 50: const Color(0xFFE8EAF6), - 100: const Color(0xFFC5CAE9), - 200: const Color(0xFF9FA8DA), - 300: const Color(0xFF7986CB), - 400: const Color(0xFF5C6BC0), - 500: const Color(0xFF3F51B5), - 600: const Color(0xFF3949AB), - 700: const Color(0xFF303F9F), - 800: const Color(0xFF283593), - 900: const Color(0xFF1A237E), - }; + static const int _indigoPrimaryValue = 0xFF3F51B5; + static const MaterialColor indigo = const MaterialColor( + _indigoPrimaryValue, + const { + 50: const Color(0xFFE8EAF6), + 100: const Color(0xFFC5CAE9), + 200: const Color(0xFF9FA8DA), + 300: const Color(0xFF7986CB), + 400: const Color(0xFF5C6BC0), + 500: const Color(_indigoPrimaryValue), + 600: const Color(0xFF3949AB), + 700: const Color(0xFF303F9F), + 800: const Color(0xFF283593), + 900: const Color(0xFF1A237E), + }, + ); - /// The indigo accent swatch. + /// The indigo accent color and swatch. /// /// ```dart /// new Icon( @@ -361,14 +481,18 @@ class Colors { /// * [indigo], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map indigoAccent = const { - 100: const Color(0xFF8C9EFF), - 200: const Color(0xFF536DFE), - 400: const Color(0xFF3D5AFE), - 700: const Color(0xFF304FFE), - }; + static const int _indigoAccentPrimaryValue = 0xFF536DFE; + static const MaterialAccentColor indigoAccent = const MaterialAccentColor( + _indigoAccentPrimaryValue, + const { + 100: const Color(0xFF8C9EFF), + 200: const Color(_indigoAccentPrimaryValue), + 400: const Color(0xFF3D5AFE), + 700: const Color(0xFF304FFE), + }, + ); - /// The blue primary swatch. + /// The blue primary color and swatch. /// /// ```dart /// new Icon( @@ -382,20 +506,24 @@ class Colors { /// * [blueAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map blue = const { - 50: const Color(0xFFE3F2FD), - 100: const Color(0xFFBBDEFB), - 200: const Color(0xFF90CAF9), - 300: const Color(0xFF64B5F6), - 400: const Color(0xFF42A5F5), - 500: const Color(0xFF2196F3), - 600: const Color(0xFF1E88E5), - 700: const Color(0xFF1976D2), - 800: const Color(0xFF1565C0), - 900: const Color(0xFF0D47A1), - }; + static const int _bluePrimaryValue = 0xFF2196F3; + static const MaterialColor blue = const MaterialColor( + _bluePrimaryValue, + const { + 50: const Color(0xFFE3F2FD), + 100: const Color(0xFFBBDEFB), + 200: const Color(0xFF90CAF9), + 300: const Color(0xFF64B5F6), + 400: const Color(0xFF42A5F5), + 500: const Color(_bluePrimaryValue), + 600: const Color(0xFF1E88E5), + 700: const Color(0xFF1976D2), + 800: const Color(0xFF1565C0), + 900: const Color(0xFF0D47A1), + }, + ); - /// The blue accent swatch. + /// The blue accent color and swatch. /// /// ```dart /// new Icon( @@ -409,14 +537,18 @@ class Colors { /// * [blue], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map blueAccent = const { - 100: const Color(0xFF82B1FF), - 200: const Color(0xFF448AFF), - 400: const Color(0xFF2979FF), - 700: const Color(0xFF2962FF), - }; + static const int _blueAccentPrimaryValue = 0xFF448AFF; + static const MaterialAccentColor blueAccent = const MaterialAccentColor( + _blueAccentPrimaryValue, + const { + 100: const Color(0xFF82B1FF), + 200: const Color(_blueAccentPrimaryValue), + 400: const Color(0xFF2979FF), + 700: const Color(0xFF2962FF), + }, + ); - /// The light blue primary swatch. + /// The light blue primary color and swatch. /// /// ```dart /// new Icon( @@ -430,18 +562,22 @@ class Colors { /// * [lightBlueAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map lightBlue = const { - 50: const Color(0xFFE1F5FE), - 100: const Color(0xFFB3E5FC), - 200: const Color(0xFF81D4FA), - 300: const Color(0xFF4FC3F7), - 400: const Color(0xFF29B6F6), - 500: const Color(0xFF03A9F4), - 600: const Color(0xFF039BE5), - 700: const Color(0xFF0288D1), - 800: const Color(0xFF0277BD), - 900: const Color(0xFF01579B), - }; + static const int _lightBluePrimaryValue = 0xFF03A9F4; + static const MaterialColor lightBlue = const MaterialColor( + _lightBluePrimaryValue, + const { + 50: const Color(0xFFE1F5FE), + 100: const Color(0xFFB3E5FC), + 200: const Color(0xFF81D4FA), + 300: const Color(0xFF4FC3F7), + 400: const Color(0xFF29B6F6), + 500: const Color(_lightBluePrimaryValue), + 600: const Color(0xFF039BE5), + 700: const Color(0xFF0288D1), + 800: const Color(0xFF0277BD), + 900: const Color(0xFF01579B), + }, + ); /// The light blue accent swatch. /// @@ -457,14 +593,18 @@ class Colors { /// * [lightBlue], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map lightBlueAccent = const { - 100: const Color(0xFF80D8FF), - 200: const Color(0xFF40C4FF), - 400: const Color(0xFF00B0FF), - 700: const Color(0xFF0091EA), - }; + static const int _lightBlueAccentPrimaryValue = 0xFF40C4FF; + static const MaterialAccentColor lightBlueAccent = const MaterialAccentColor( + _lightBlueAccentPrimaryValue, + const { + 100: const Color(0xFF80D8FF), + 200: const Color(_lightBlueAccentPrimaryValue), + 400: const Color(0xFF00B0FF), + 700: const Color(0xFF0091EA), + }, + ); - /// The cyan primary swatch. + /// The cyan primary color and swatch. /// /// ```dart /// new Icon( @@ -478,20 +618,24 @@ class Colors { /// * [cyanAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map cyan = const { - 50: const Color(0xFFE0F7FA), - 100: const Color(0xFFB2EBF2), - 200: const Color(0xFF80DEEA), - 300: const Color(0xFF4DD0E1), - 400: const Color(0xFF26C6DA), - 500: const Color(0xFF00BCD4), - 600: const Color(0xFF00ACC1), - 700: const Color(0xFF0097A7), - 800: const Color(0xFF00838F), - 900: const Color(0xFF006064), - }; + static const int _cyanPrimaryValue = 0xFF00BCD4; + static const MaterialColor cyan = const MaterialColor( + _cyanPrimaryValue, + const { + 50: const Color(0xFFE0F7FA), + 100: const Color(0xFFB2EBF2), + 200: const Color(0xFF80DEEA), + 300: const Color(0xFF4DD0E1), + 400: const Color(0xFF26C6DA), + 500: const Color(_cyanPrimaryValue), + 600: const Color(0xFF00ACC1), + 700: const Color(0xFF0097A7), + 800: const Color(0xFF00838F), + 900: const Color(0xFF006064), + }, + ); - /// The cyan accent swatch. + /// The cyan accent color and swatch. /// /// ```dart /// new Icon( @@ -505,14 +649,18 @@ class Colors { /// * [cyan], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map cyanAccent = const { - 100: const Color(0xFF84FFFF), - 200: const Color(0xFF18FFFF), - 400: const Color(0xFF00E5FF), - 700: const Color(0xFF00B8D4), - }; + static const int _cyanAccentPrimaryValue = 0xFF18FFFF; + static const MaterialAccentColor cyanAccent = const MaterialAccentColor( + _cyanAccentPrimaryValue, + const { + 100: const Color(0xFF84FFFF), + 200: const Color(_cyanAccentPrimaryValue), + 400: const Color(0xFF00E5FF), + 700: const Color(0xFF00B8D4), + }, + ); - /// The teal primary swatch. + /// The teal primary color and swatch. /// /// ```dart /// new Icon( @@ -526,20 +674,24 @@ class Colors { /// * [tealAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map teal = const { - 50: const Color(0xFFE0F2F1), - 100: const Color(0xFFB2DFDB), - 200: const Color(0xFF80CBC4), - 300: const Color(0xFF4DB6AC), - 400: const Color(0xFF26A69A), - 500: const Color(0xFF009688), - 600: const Color(0xFF00897B), - 700: const Color(0xFF00796B), - 800: const Color(0xFF00695C), - 900: const Color(0xFF004D40), - }; + static const int _tealPrimaryValue = 0xFF009688; + static const MaterialColor teal = const MaterialColor( + _tealPrimaryValue, + const { + 50: const Color(0xFFE0F2F1), + 100: const Color(0xFFB2DFDB), + 200: const Color(0xFF80CBC4), + 300: const Color(0xFF4DB6AC), + 400: const Color(0xFF26A69A), + 500: const Color(_tealPrimaryValue), + 600: const Color(0xFF00897B), + 700: const Color(0xFF00796B), + 800: const Color(0xFF00695C), + 900: const Color(0xFF004D40), + }, + ); - /// The teal accent swatch. + /// The teal accent color and swatch. /// /// ```dart /// new Icon( @@ -553,14 +705,18 @@ class Colors { /// * [teal], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map tealAccent = const { - 100: const Color(0xFFA7FFEB), - 200: const Color(0xFF64FFDA), - 400: const Color(0xFF1DE9B6), - 700: const Color(0xFF00BFA5), - }; + static const int _tealAccentPrimaryValue = 0xFF64FFDA; + static const MaterialAccentColor tealAccent = const MaterialAccentColor( + _tealAccentPrimaryValue, + const { + 100: const Color(0xFFA7FFEB), + 200: const Color(_tealAccentPrimaryValue), + 400: const Color(0xFF1DE9B6), + 700: const Color(0xFF00BFA5), + }, + ); - /// The green primary swatch. + /// The green primary color and swatch. /// /// ```dart /// new Icon( @@ -574,20 +730,24 @@ class Colors { /// * [greenAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map green = const { - 50: const Color(0xFFE8F5E9), - 100: const Color(0xFFC8E6C9), - 200: const Color(0xFFA5D6A7), - 300: const Color(0xFF81C784), - 400: const Color(0xFF66BB6A), - 500: const Color(0xFF4CAF50), - 600: const Color(0xFF43A047), - 700: const Color(0xFF388E3C), - 800: const Color(0xFF2E7D32), - 900: const Color(0xFF1B5E20), - }; + static const int _greenPrimaryValue = 0xFF4CAF50; + static const MaterialColor green = const MaterialColor( + _greenPrimaryValue, + const { + 50: const Color(0xFFE8F5E9), + 100: const Color(0xFFC8E6C9), + 200: const Color(0xFFA5D6A7), + 300: const Color(0xFF81C784), + 400: const Color(0xFF66BB6A), + 500: const Color(_greenPrimaryValue), + 600: const Color(0xFF43A047), + 700: const Color(0xFF388E3C), + 800: const Color(0xFF2E7D32), + 900: const Color(0xFF1B5E20), + }, + ); - /// The green accent swatch. + /// The green accent color and swatch. /// /// ```dart /// new Icon( @@ -601,14 +761,18 @@ class Colors { /// * [green], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map greenAccent = const { - 100: const Color(0xFFB9F6CA), - 200: const Color(0xFF69F0AE), - 400: const Color(0xFF00E676), - 700: const Color(0xFF00C853), - }; + static const int _greenAccentPrimaryValue = 0xFF69F0AE; + static const MaterialAccentColor greenAccent = const MaterialAccentColor( + _greenAccentPrimaryValue, + const { + 100: const Color(0xFFB9F6CA), + 200: const Color(_greenAccentPrimaryValue), + 400: const Color(0xFF00E676), + 700: const Color(0xFF00C853), + }, + ); - /// The light green primary swatch. + /// The light green primary color and swatch. /// /// ```dart /// new Icon( @@ -622,20 +786,24 @@ class Colors { /// * [lightGreenAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map lightGreen = const { - 50: const Color(0xFFF1F8E9), - 100: const Color(0xFFDCEDC8), - 200: const Color(0xFFC5E1A5), - 300: const Color(0xFFAED581), - 400: const Color(0xFF9CCC65), - 500: const Color(0xFF8BC34A), - 600: const Color(0xFF7CB342), - 700: const Color(0xFF689F38), - 800: const Color(0xFF558B2F), - 900: const Color(0xFF33691E), - }; + static const int _lightGreenPrimaryValue = 0xFF8BC34A; + static const MaterialColor lightGreen = const MaterialColor( + _lightGreenPrimaryValue, + const { + 50: const Color(0xFFF1F8E9), + 100: const Color(0xFFDCEDC8), + 200: const Color(0xFFC5E1A5), + 300: const Color(0xFFAED581), + 400: const Color(0xFF9CCC65), + 500: const Color(_lightGreenPrimaryValue), + 600: const Color(0xFF7CB342), + 700: const Color(0xFF689F38), + 800: const Color(0xFF558B2F), + 900: const Color(0xFF33691E), + }, + ); - /// The light green accent swatch. + /// The light green accent color and swatch. /// /// ```dart /// new Icon( @@ -649,14 +817,18 @@ class Colors { /// * [lightGreen], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map lightGreenAccent = const { - 100: const Color(0xFFCCFF90), - 200: const Color(0xFFB2FF59), - 400: const Color(0xFF76FF03), - 700: const Color(0xFF64DD17), - }; + static const int _lightGreenAccentPrimaryValue = 0xFFB2FF59; + static const MaterialAccentColor lightGreenAccent = const MaterialAccentColor( + _lightGreenAccentPrimaryValue, + const { + 100: const Color(0xFFCCFF90), + 200: const Color(_lightGreenAccentPrimaryValue), + 400: const Color(0xFF76FF03), + 700: const Color(0xFF64DD17), + }, + ); - /// The lime primary swatch. + /// The lime primary color and swatch. /// /// ```dart /// new Icon( @@ -670,20 +842,24 @@ class Colors { /// * [limeAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map lime = const { - 50: const Color(0xFFF9FBE7), - 100: const Color(0xFFF0F4C3), - 200: const Color(0xFFE6EE9C), - 300: const Color(0xFFDCE775), - 400: const Color(0xFFD4E157), - 500: const Color(0xFFCDDC39), - 600: const Color(0xFFC0CA33), - 700: const Color(0xFFAFB42B), - 800: const Color(0xFF9E9D24), - 900: const Color(0xFF827717), - }; + static const int _limePrimaryValue = 0xFFCDDC39; + static const MaterialColor lime = const MaterialColor( + _limePrimaryValue, + const { + 50: const Color(0xFFF9FBE7), + 100: const Color(0xFFF0F4C3), + 200: const Color(0xFFE6EE9C), + 300: const Color(0xFFDCE775), + 400: const Color(0xFFD4E157), + 500: const Color(_limePrimaryValue), + 600: const Color(0xFFC0CA33), + 700: const Color(0xFFAFB42B), + 800: const Color(0xFF9E9D24), + 900: const Color(0xFF827717), + }, + ); - /// The lime accent primary swatch. + /// The lime accent primary color and swatch. /// /// ```dart /// new Icon( @@ -697,14 +873,18 @@ class Colors { /// * [lime], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map limeAccent = const { - 100: const Color(0xFFF4FF81), - 200: const Color(0xFFEEFF41), - 400: const Color(0xFFC6FF00), - 700: const Color(0xFFAEEA00), - }; + static const int _limeAccentPrimaryValue = 0xFFEEFF41; + static const MaterialAccentColor limeAccent = const MaterialAccentColor( + _limeAccentPrimaryValue, + const { + 100: const Color(0xFFF4FF81), + 200: const Color(_limeAccentPrimaryValue), + 400: const Color(0xFFC6FF00), + 700: const Color(0xFFAEEA00), + }, + ); - /// The yellow primary swatch. + /// The yellow primary color and swatch. /// /// ```dart /// new Icon( @@ -718,20 +898,24 @@ class Colors { /// * [yellowAccentAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map yellow = const { - 50: const Color(0xFFFFFDE7), - 100: const Color(0xFFFFF9C4), - 200: const Color(0xFFFFF59D), - 300: const Color(0xFFFFF176), - 400: const Color(0xFFFFEE58), - 500: const Color(0xFFFFEB3B), - 600: const Color(0xFFFDD835), - 700: const Color(0xFFFBC02D), - 800: const Color(0xFFF9A825), - 900: const Color(0xFFF57F17), - }; + static const int _yellowPrimaryValue = 0xFFFFEB3B; + static const MaterialColor yellow = const MaterialColor( + _yellowPrimaryValue, + const { + 50: const Color(0xFFFFFDE7), + 100: const Color(0xFFFFF9C4), + 200: const Color(0xFFFFF59D), + 300: const Color(0xFFFFF176), + 400: const Color(0xFFFFEE58), + 500: const Color(_yellowPrimaryValue), + 600: const Color(0xFFFDD835), + 700: const Color(0xFFFBC02D), + 800: const Color(0xFFF9A825), + 900: const Color(0xFFF57F17), + }, + ); - /// The yellow accent swatch. + /// The yellow accent color and swatch. /// /// ```dart /// new Icon( @@ -745,14 +929,18 @@ class Colors { /// * [yellow], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map yellowAccent = const { - 100: const Color(0xFFFFFF8D), - 200: const Color(0xFFFFFF00), - 400: const Color(0xFFFFEA00), - 700: const Color(0xFFFFD600), - }; + static const int _yellowAccentPrimaryValue = 0xFFFFFF00; + static const MaterialAccentColor yellowAccent = const MaterialAccentColor( + _yellowAccentPrimaryValue, + const { + 100: const Color(0xFFFFFF8D), + 200: const Color(_yellowAccentPrimaryValue), + 400: const Color(0xFFFFEA00), + 700: const Color(0xFFFFD600), + }, + ); - /// The amber primary swatch. + /// The amber primary color and swatch. /// /// ```dart /// new Icon( @@ -766,20 +954,24 @@ class Colors { /// * [amberAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map amber = const { - 50: const Color(0xFFFFF8E1), - 100: const Color(0xFFFFECB3), - 200: const Color(0xFFFFE082), - 300: const Color(0xFFFFD54F), - 400: const Color(0xFFFFCA28), - 500: const Color(0xFFFFC107), - 600: const Color(0xFFFFB300), - 700: const Color(0xFFFFA000), - 800: const Color(0xFFFF8F00), - 900: const Color(0xFFFF6F00), - }; + static const int _amberPrimaryValue = 0xFFFFC107; + static const MaterialColor amber = const MaterialColor( + _amberPrimaryValue, + const { + 50: const Color(0xFFFFF8E1), + 100: const Color(0xFFFFECB3), + 200: const Color(0xFFFFE082), + 300: const Color(0xFFFFD54F), + 400: const Color(0xFFFFCA28), + 500: const Color(_amberPrimaryValue), + 600: const Color(0xFFFFB300), + 700: const Color(0xFFFFA000), + 800: const Color(0xFFFF8F00), + 900: const Color(0xFFFF6F00), + }, + ); - /// The amber accent swatch. + /// The amber accent color and swatch. /// /// ```dart /// new Icon( @@ -793,14 +985,18 @@ class Colors { /// * [amber], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map amberAccent = const { - 100: const Color(0xFFFFE57F), - 200: const Color(0xFFFFD740), - 400: const Color(0xFFFFC400), - 700: const Color(0xFFFFAB00), - }; + static const int _amberAccentPrimaryValue = 0xFFFFD740; + static const MaterialAccentColor amberAccent = const MaterialAccentColor( + _amberAccentPrimaryValue, + const { + 100: const Color(0xFFFFE57F), + 200: const Color(_amberAccentPrimaryValue), + 400: const Color(0xFFFFC400), + 700: const Color(0xFFFFAB00), + }, + ); - /// The orange primary swatch. + /// The orange primary color and swatch. /// /// ```dart /// new Icon( @@ -814,20 +1010,24 @@ class Colors { /// * [orangeAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map orange = const { - 50: const Color(0xFFFFF3E0), - 100: const Color(0xFFFFE0B2), - 200: const Color(0xFFFFCC80), - 300: const Color(0xFFFFB74D), - 400: const Color(0xFFFFA726), - 500: const Color(0xFFFF9800), - 600: const Color(0xFFFB8C00), - 700: const Color(0xFFF57C00), - 800: const Color(0xFFEF6C00), - 900: const Color(0xFFE65100), - }; + static const int _orangePrimaryValue = 0xFFFF9800; + static const MaterialColor orange = const MaterialColor( + _orangePrimaryValue, + const { + 50: const Color(0xFFFFF3E0), + 100: const Color(0xFFFFE0B2), + 200: const Color(0xFFFFCC80), + 300: const Color(0xFFFFB74D), + 400: const Color(0xFFFFA726), + 500: const Color(_orangePrimaryValue), + 600: const Color(0xFFFB8C00), + 700: const Color(0xFFF57C00), + 800: const Color(0xFFEF6C00), + 900: const Color(0xFFE65100), + }, + ); - /// The orange accent swatch. + /// The orange accent color and swatch. /// /// ```dart /// new Icon( @@ -841,14 +1041,18 @@ class Colors { /// * [orange], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map orangeAccent = const { - 100: const Color(0xFFFFD180), - 200: const Color(0xFFFFAB40), - 400: const Color(0xFFFF9100), - 700: const Color(0xFFFF6D00), - }; + static const int _orangeAccentPrimaryValue = 0xFFFFAB40; + static const MaterialAccentColor orangeAccent = const MaterialAccentColor( + _orangeAccentPrimaryValue, + const { + 100: const Color(0xFFFFD180), + 200: const Color(_orangeAccentPrimaryValue), + 400: const Color(0xFFFF9100), + 700: const Color(0xFFFF6D00), + }, + ); - /// The deep orange primary swatch. + /// The deep orange primary color and swatch. /// /// ```dart /// new Icon( @@ -862,20 +1066,24 @@ class Colors { /// * [deepOrangeAccent], the corresponding accent colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map deepOrange = const { - 50: const Color(0xFFFBE9E7), - 100: const Color(0xFFFFCCBC), - 200: const Color(0xFFFFAB91), - 300: const Color(0xFFFF8A65), - 400: const Color(0xFFFF7043), - 500: const Color(0xFFFF5722), - 600: const Color(0xFFF4511E), - 700: const Color(0xFFE64A19), - 800: const Color(0xFFD84315), - 900: const Color(0xFFBF360C), - }; + static const int _deepOrangePrimaryValue = 0xFFFF5722; + static const MaterialColor deepOrange = const MaterialColor( + _deepOrangePrimaryValue, + const { + 50: const Color(0xFFFBE9E7), + 100: const Color(0xFFFFCCBC), + 200: const Color(0xFFFFAB91), + 300: const Color(0xFFFF8A65), + 400: const Color(0xFFFF7043), + 500: const Color(_deepOrangePrimaryValue), + 600: const Color(0xFFF4511E), + 700: const Color(0xFFE64A19), + 800: const Color(0xFFD84315), + 900: const Color(0xFFBF360C), + }, + ); - /// The deep orange accent swatch. + /// The deep orange accent color and swatch. /// /// ```dart /// new Icon( @@ -889,14 +1097,18 @@ class Colors { /// * [deepOrange], the corresponding primary colors. /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map deepOrangeAccent = const { - 100: const Color(0xFFFF9E80), - 200: const Color(0xFFFF6E40), - 400: const Color(0xFFFF3D00), - 700: const Color(0xFFDD2C00), - }; + static const int _deepOrangeAccentPrimaryValue = 0xFFFF6E40; + static const MaterialAccentColor deepOrangeAccent = const MaterialAccentColor( + _deepOrangeAccentPrimaryValue, + const { + 100: const Color(0xFFFF9E80), + 200: const Color(_deepOrangeAccentPrimaryValue), + 400: const Color(0xFFFF3D00), + 700: const Color(0xFFDD2C00), + }, + ); - /// The brown primary swatch. + /// The brown primary color and swatch. /// /// ```dart /// new Icon( @@ -905,26 +1117,30 @@ class Colors { /// ), /// ``` /// - /// This swatch has no corresponding accent swatch. + /// This swatch has no corresponding accent color and swatch. /// /// See also: /// /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map brown = const { - 50: const Color(0xFFEFEBE9), - 100: const Color(0xFFD7CCC8), - 200: const Color(0xFFBCAAA4), - 300: const Color(0xFFA1887F), - 400: const Color(0xFF8D6E63), - 500: const Color(0xFF795548), - 600: const Color(0xFF6D4C41), - 700: const Color(0xFF5D4037), - 800: const Color(0xFF4E342E), - 900: const Color(0xFF3E2723), - }; + static const int _brownPrimaryValue = 0xFF795548; + static const MaterialColor brown = const MaterialColor( + _brownPrimaryValue, + const { + 50: const Color(0xFFEFEBE9), + 100: const Color(0xFFD7CCC8), + 200: const Color(0xFFBCAAA4), + 300: const Color(0xFFA1887F), + 400: const Color(0xFF8D6E63), + 500: const Color(_brownPrimaryValue), + 600: const Color(0xFF6D4C41), + 700: const Color(0xFF5D4037), + 800: const Color(0xFF4E342E), + 900: const Color(0xFF3E2723), + }, + ); - /// The grey primary swatch. + /// The grey primary color and swatch. /// /// ```dart /// new Icon( @@ -944,22 +1160,26 @@ class Colors { /// /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map grey = const { - 50: const Color(0xFFFAFAFA), - 100: const Color(0xFFF5F5F5), - 200: const Color(0xFFEEEEEE), - 300: const Color(0xFFE0E0E0), - 350: const Color(0xFFD6D6D6), // only for raised button while pressed in light theme - 400: const Color(0xFFBDBDBD), - 500: const Color(0xFF9E9E9E), - 600: const Color(0xFF757575), - 700: const Color(0xFF616161), - 800: const Color(0xFF424242), - 850: const Color(0xFF303030), // only for background color in dark theme - 900: const Color(0xFF212121), - }; + static const int _greyPrimaryValue = 0xFF9E9E9E; + static const MaterialColor grey = const MaterialColor( + _greyPrimaryValue, + const { + 50: const Color(0xFFFAFAFA), + 100: const Color(0xFFF5F5F5), + 200: const Color(0xFFEEEEEE), + 300: const Color(0xFFE0E0E0), + 350: const Color(0xFFD6D6D6), // only for raised button while pressed in light theme + 400: const Color(0xFFBDBDBD), + 500: const Color(_greyPrimaryValue), + 600: const Color(0xFF757575), + 700: const Color(0xFF616161), + 800: const Color(0xFF424242), + 850: const Color(0xFF303030), // only for background color in dark theme + 900: const Color(0xFF212121), + }, + ); - /// The blue-grey primary swatch. + /// The blue-grey primary color and swatch. /// /// ```dart /// new Icon( @@ -974,21 +1194,25 @@ class Colors { /// /// * [Theme.of], which allows you to select colors from the current theme /// rather than hard-coding colors in your build methods. - static const Map blueGrey = const { - 50: const Color(0xFFECEFF1), - 100: const Color(0xFFCFD8DC), - 200: const Color(0xFFB0BEC5), - 300: const Color(0xFF90A4AE), - 400: const Color(0xFF78909C), - 500: const Color(0xFF607D8B), - 600: const Color(0xFF546E7A), - 700: const Color(0xFF455A64), - 800: const Color(0xFF37474F), - 900: const Color(0xFF263238), - }; + static const int _blueGreyPrimaryValue = 0xFF607D8B; + static const MaterialColor blueGrey = const MaterialColor( + _blueGreyPrimaryValue, + const { + 50: const Color(0xFFECEFF1), + 100: const Color(0xFFCFD8DC), + 200: const Color(0xFFB0BEC5), + 300: const Color(0xFF90A4AE), + 400: const Color(0xFF78909C), + 500: const Color(_blueGreyPrimaryValue), + 600: const Color(0xFF546E7A), + 700: const Color(0xFF455A64), + 800: const Color(0xFF37474F), + 900: const Color(0xFF263238), + }, + ); /// The material design primary color swatches (except grey). - static const List> primaries = const >[ + static const List primaries = const [ red, pink, purple, @@ -1011,7 +1235,7 @@ class Colors { ]; /// The material design accent color swatches. - static const List> accents = const >[ + static const List accents = const [ redAccent, pinkAccent, purpleAccent, diff --git a/packages/flutter/lib/src/material/flutter_logo.dart b/packages/flutter/lib/src/material/flutter_logo.dart index 83e19da200..2e734ed39f 100644 --- a/packages/flutter/lib/src/material/flutter_logo.dart +++ b/packages/flutter/lib/src/material/flutter_logo.dart @@ -22,7 +22,7 @@ class FlutterLogo extends StatelessWidget { const FlutterLogo({ Key key, this.size, - this.swatch: Colors.blue, + this.colors, this.textColor: const Color(0xFF616161), this.style: FlutterLogoStyle.markOnly, this.duration: const Duration(milliseconds: 750), @@ -38,20 +38,16 @@ class FlutterLogo extends StatelessWidget { /// 24.0. final double size; - /// The colors to use to paint the logo. This map should contain at least two - /// values, one for 400 and one for 900. + /// The color swatch to use to paint the logo, Colors.blue by default. /// - /// If possible, the default should be used. It corresponds to the - /// [Colors.blue] swatch. - /// - /// If for some reason that color scheme is impractical, the [Colors.amber], - /// [Colors.red], or [Colors.indigo] swatches can be used. These are Flutter's - /// secondary colors. + /// If for some reason the default colors are impractical, then one + /// of [Colors.amber], [Colors.red], or [Colors.indigo] swatches can be used. + /// These are Flutter's secondary colors. /// /// In extreme cases where none of those four color schemes will work, /// [Colors.pink], [Colors.purple], or [Colors.cyan] swatches can be used. /// These are Flutter's tertiary colors. - final Map swatch; + final MaterialColor colors; /// The color used to paint the "Flutter" text on the logo, if [style] is /// [FlutterLogoStyle.horizontal] or [FlutterLogoStyle.stacked]. The @@ -75,13 +71,15 @@ class FlutterLogo extends StatelessWidget { Widget build(BuildContext context) { final IconThemeData iconTheme = IconTheme.of(context); final double iconSize = size ?? iconTheme.size; + final MaterialColor logoColors = colors ?? Colors.blue; return new AnimatedContainer( width: iconSize, height: iconSize, duration: duration, curve: curve, decoration: new FlutterLogoDecoration( - swatch: swatch, + lightColor: logoColors.shade400, + darkColor: logoColors.shade900, style: style, textColor: textColor, ), diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index 2daf126b30..7cfdb05d8a 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -76,7 +76,7 @@ Map kListTileExtent = const /// * [CircleAvatar], which shows an icon representing a person and is often /// used as the [leading] element of a ListTile. /// * [Divider], which can be used to separate [ListTile]s. -/// * [ListTile.divideTiles], a utility for inserting [Divider]s in between [ListTiles]s. +/// * [ListTile.divideTiles], a utility for inserting [Divider]s in between [ListTile]s. /// * class ListTile extends StatelessWidget { /// Creates a list tile. diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index 969b64cb6e..0aead08035 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -70,7 +70,7 @@ class ThemeData { /// more discussion on how to pick the right colors. factory ThemeData({ Brightness brightness, - Map primarySwatch, + MaterialColor primarySwatch, Color primaryColor, Brightness primaryColorBrightness, Color accentColor, diff --git a/packages/flutter/lib/src/painting/flutter_logo.dart b/packages/flutter/lib/src/painting/flutter_logo.dart index 8b390d4c0f..a9aac36c19 100644 --- a/packages/flutter/lib/src/painting/flutter_logo.dart +++ b/packages/flutter/lib/src/painting/flutter_logo.dart @@ -31,24 +31,19 @@ enum FlutterLogoStyle { stacked, } -const int _lightShade = 400; -const int _darkShade = 900; -const Map _kDefaultSwatch = const { - _lightShade: const Color(0xFF42A5F5), - _darkShade: const Color(0xFF0D47A1) -}; - /// An immutable description of how to paint Flutter's logo. class FlutterLogoDecoration extends Decoration { /// Creates a decoration that knows how to paint Flutter's logo. /// - /// The [swatch] controls the color used for the logo. The [style] controls - /// whether and where to draw the "Flutter" label. If one is shown, the - /// [textColor] controls the color of the label. + /// The [lightColor] and [darkColor] are used to fill the logo. The [style] + /// controls whether and where to draw the "Flutter" label. If one is shown, + /// the [textColor] controls the color of the label. /// - /// The [swatch], [textColor], and [style] arguments must not be null. + /// The [lightColor], [darkColor], [textColor], and [style] arguments must not + /// be null. const FlutterLogoDecoration({ - this.swatch: _kDefaultSwatch, + this.lightColor: const Color(0xFF42A5F5), // Colors.blue[400] + this.darkColor: const Color(0xFF0D47A1), // Colors.blue[900] this.textColor: const Color(0xFF616161), this.style: FlutterLogoStyle.markOnly, this.margin: EdgeInsets.zero, @@ -56,22 +51,26 @@ class FlutterLogoDecoration extends Decoration { // (see https://github.com/dart-lang/sdk/issues/26980 for details about that ignore statement) _opacity = 1.0; - FlutterLogoDecoration._(this.swatch, this.textColor, this.style, this._position, this._opacity, this.margin); + FlutterLogoDecoration._(this.lightColor, this.darkColor, this.textColor, this.style, this._position, this._opacity, this.margin); - /// The colors to use to paint the logo. This map should contain at least two - /// values, one for 400 and one for 900. + /// The lighter of the two colors used to paint the logo. /// - /// If possible, the default should be used. It corresponds to the - /// [Colors.blue] swatch from the Material library. + /// If possible, the default should be used. It corresponds to the 400 and 900 + /// values of [Colors.blue] from the Material library. /// - /// If for some reason that color scheme is impractical, the [Colors.amber], - /// [Colors.red], or [Colors.indigo] swatches can be used. These are Flutter's - /// secondary colors. + /// If for some reason that color scheme is impractical, the same entries from + /// [Colors.amber], [Colors.red], or [Colors.indigo] colors can be used. These + /// are Flutter's secondary colors. /// /// In extreme cases where none of those four color schemes will work, - /// [Colors.pink], [Colors.purple], or [Colors.cyan] swatches can be used. + /// [Colors.pink], [Colors.purple], or [Colors.cyan] can be used. /// These are Flutter's tertiary colors. - final Map swatch; + final Color lightColor; + + /// The darker of the two colors used to paint the logo. + /// + /// See [lightColor] for more information about selecting the logo's colors. + final Color darkColor; /// The color used to paint the "Flutter" text on the logo, if [style] is /// [FlutterLogoStyle.horizontal] or [FlutterLogoStyle.stacked]. The @@ -97,9 +96,8 @@ class FlutterLogoDecoration extends Decoration { @override bool debugAssertIsValid() { - assert(swatch != null - && swatch[_lightShade] != null - && swatch[_darkShade] != null + assert(lightColor != null + && darkColor != null && textColor != null && style != null && _position != null @@ -126,7 +124,8 @@ class FlutterLogoDecoration extends Decoration { return null; if (a == null) { return new FlutterLogoDecoration._( - b.swatch, + b.lightColor, + b.darkColor, b.textColor, b.style, b._position, @@ -136,7 +135,8 @@ class FlutterLogoDecoration extends Decoration { } if (b == null) { return new FlutterLogoDecoration._( - a.swatch, + a.lightColor, + a.darkColor, a.textColor, a.style, a._position, @@ -145,7 +145,8 @@ class FlutterLogoDecoration extends Decoration { ); } return new FlutterLogoDecoration._( - _lerpSwatch(a.swatch, b.swatch, t), + Color.lerp(a.lightColor, b.lightColor, t), + Color.lerp(a.darkColor, b.darkColor, t), Color.lerp(a.textColor, b.textColor, t), t < 0.5 ? a.style : b.style, a._position + (b._position - a._position) * t, @@ -154,15 +155,6 @@ class FlutterLogoDecoration extends Decoration { ); } - static Map _lerpSwatch(Map a, Map b, double t) { - assert(a != null); - assert(b != null); - return { - _lightShade: Color.lerp(a[_lightShade], b[_lightShade], t), - _darkShade: Color.lerp(a[_darkShade], b[_darkShade], t), - }; - } - @override FlutterLogoDecoration lerpFrom(Decoration a, double t) { assert(debugAssertIsValid()); @@ -199,8 +191,8 @@ class FlutterLogoDecoration extends Decoration { if (other is! FlutterLogoDecoration) return false; final FlutterLogoDecoration typedOther = other; - return swatch[_lightShade] == typedOther.swatch[_lightShade] - && swatch[_darkShade] == typedOther.swatch[_darkShade] + return lightColor == typedOther.lightColor + && darkColor == typedOther.darkColor && textColor == typedOther.textColor && _position == typedOther._position && _opacity == typedOther._opacity; @@ -210,8 +202,8 @@ class FlutterLogoDecoration extends Decoration { int get hashCode { assert(debugAssertIsValid()); return hashValues( - swatch[_lightShade], - swatch[_darkShade], + lightColor, + darkColor, textColor, _position, _opacity @@ -221,9 +213,7 @@ class FlutterLogoDecoration extends Decoration { @override String toString([String prefix = '', String prefixIndent ]) { final String extra = _inTransition ? ', transition $_position:$_opacity' : ''; - if (swatch == null) - return '$prefix$runtimeType(null, $style$extra)'; - return '$prefix$runtimeType(${swatch[_lightShade]}/${swatch[_darkShade]} on $textColor, $style$extra)'; + return '$prefix$runtimeType($lightColor/$darkColor on $textColor, $style$extra)'; } } @@ -279,11 +269,11 @@ class _FlutterLogoPainter extends BoxPainter { // Set up the styles. final Paint lightPaint = new Paint() - ..color = _config.swatch[_lightShade].withOpacity(0.8); + ..color = _config.lightColor.withOpacity(0.8); final Paint mediumPaint = new Paint() - ..color = _config.swatch[_lightShade]; + ..color = _config.lightColor; final Paint darkPaint = new Paint() - ..color = _config.swatch[_darkShade]; + ..color = _config.darkColor; final ui.Gradient triangleGradient = new ui.Gradient.linear( const [ diff --git a/packages/flutter/test/material/colors_test.dart b/packages/flutter/test/material/colors_test.dart new file mode 100644 index 0000000000..cfab64edf6 --- /dev/null +++ b/packages/flutter/test/material/colors_test.dart @@ -0,0 +1,86 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:test/test.dart'; + +import 'package:flutter/material.dart'; + +const List primaryKeys = const [50, 100, 200, 300, 400, 500, 600, 700, 800, 900]; +const List accentKeys = const [100, 200, 400, 700]; + +void main() { + test('MaterialColor basic functionality', () { + final MaterialColor color = new MaterialColor( + 500, + const { + 50: const Color(50), + 100: const Color(100), + 200: const Color(200), + 300: const Color(300), + 400: const Color(400), + 500: const Color(500), + 600: const Color(600), + 700: const Color(700), + 800: const Color(800), + 900: const Color(900), + }, + ); + + expect(color.value, 500); + + expect(color[50].value, 50); + expect(color[100].value, 100); + expect(color[200].value, 200); + expect(color[300].value, 300); + expect(color[400].value, 400); + expect(color[500].value, 500); + expect(color[600].value, 600); + expect(color[700].value, 700); + expect(color[800].value, 800); + expect(color[900].value, 900); + + expect(color.shade50.value, 50); + expect(color.shade100.value, 100); + expect(color.shade200.value, 200); + expect(color.shade300.value, 300); + expect(color.shade400.value, 400); + expect(color.shade500.value, 500); + expect(color.shade600.value, 600); + expect(color.shade700.value, 700); + expect(color.shade800.value, 800); + expect(color.shade900.value, 900); + }); + + test('Colors swatches do not contain duplicates', () { + for (MaterialColor color in Colors.primaries) + expect(primaryKeys.map((int key) => color[key]).toSet().length, primaryKeys.length); + + expect(primaryKeys.map((int key) => Colors.grey[key]).toSet().length, primaryKeys.length); + + for (MaterialAccentColor color in Colors.accents) + expect(accentKeys.map((int key) => color[key]).toSet().length, accentKeys.length); + }); + + test('All color swatch colors are opaque and equal their primary color', () { + for (MaterialColor color in Colors.primaries) { + expect(color.value, color.shade500.value); + for (int key in primaryKeys) { + expect(color[key].alpha, 0xFF); + } + } + + expect(Colors.grey.value, Colors.grey.shade500.value); + for (int key in primaryKeys) { + expect(Colors.grey[key].alpha, 0xFF); + } + + for (MaterialAccentColor color in Colors.accents) { + expect(color.value, color.shade200.value); + for (int key in accentKeys) { + expect(color[key].alpha, 0xFF); + } + } + }); + +}