Unverified Commit 99a22938 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Added ColorScheme dartdoc (#22592)

parent 9eca0830
...@@ -17,6 +17,7 @@ import 'theme_data.dart'; ...@@ -17,6 +17,7 @@ import 'theme_data.dart';
/// with [ColorScheme.fromSwatch]. /// with [ColorScheme.fromSwatch].
@immutable @immutable
class ColorScheme extends Diagnosticable { class ColorScheme extends Diagnosticable {
/// Create a ColorScheme instance.
const ColorScheme({ const ColorScheme({
@required this.primary, @required this.primary,
@required this.primaryVariant, @required this.primaryVariant,
...@@ -45,6 +46,8 @@ class ColorScheme extends Diagnosticable { ...@@ -45,6 +46,8 @@ class ColorScheme extends Diagnosticable {
assert(onError != null), assert(onError != null),
assert(brightness != null); assert(brightness != null);
/// Create a ColorScheme based on a purple primary color that matches the
/// [baseline Material color scheme](https://material.io/design/color/the-color-system.html#color-theme-creation).
const ColorScheme.light({ const ColorScheme.light({
this.primary = const Color(0xff6200ee), this.primary = const Color(0xff6200ee),
this.primaryVariant = const Color(0xff3700b3), this.primaryVariant = const Color(0xff3700b3),
...@@ -73,6 +76,8 @@ class ColorScheme extends Diagnosticable { ...@@ -73,6 +76,8 @@ class ColorScheme extends Diagnosticable {
assert(onError != null), assert(onError != null),
assert(brightness != null); assert(brightness != null);
/// Create dark version of the
/// [baseline Material color scheme](https://material.io/design/color/the-color-system.html#color-theme-creation).
const ColorScheme.dark({ const ColorScheme.dark({
this.primary = const Color(0xffbb86fc), this.primary = const Color(0xffbb86fc),
this.primaryVariant = const Color(0xff4b01d0), this.primaryVariant = const Color(0xff4b01d0),
...@@ -101,6 +106,10 @@ class ColorScheme extends Diagnosticable { ...@@ -101,6 +106,10 @@ class ColorScheme extends Diagnosticable {
assert(onError != null), assert(onError != null),
assert(brightness != null); assert(brightness != null);
/// Create a color scheme from a [MaterialColor] swatch.
///
/// This constructor is used by [ThemeData] to create its default \
/// color scheme.
factory ColorScheme.fromSwatch({ factory ColorScheme.fromSwatch({
MaterialColor primarySwatch = Colors.blue, MaterialColor primarySwatch = Colors.blue,
Color primaryColorDark, Color primaryColorDark,
...@@ -137,20 +146,49 @@ class ColorScheme extends Diagnosticable { ...@@ -137,20 +146,49 @@ class ColorScheme extends Diagnosticable {
static Brightness _brightnessFor(Color color) => ThemeData.estimateBrightnessForColor(color); static Brightness _brightnessFor(Color color) => ThemeData.estimateBrightnessForColor(color);
/// The color displayed most frequently across your app’s screens and components.
final Color primary; final Color primary;
/// A darker version of the primary color.
final Color primaryVariant; final Color primaryVariant;
/// An accent color that, when used sparingly, calls attention to parts
/// of your app.
final Color secondary; final Color secondary;
/// A darker version of the secondary color.
final Color secondaryVariant; final Color secondaryVariant;
/// A color that typically appears behind scrollable content.
final Color background; final Color background;
/// The color to use for input validation errors, e.g. for
/// [InputDecoration.errorText].
final Color error; final Color error;
/// The background color for widgets like [Card].
final Color surface; final Color surface;
/// A color that's clearly legible when drawn on [primary].
final Color onPrimary; final Color onPrimary;
/// A color that's clearly legible when drawn on [secondary].
final Color onSecondary; final Color onSecondary;
/// A color that's clearly legible when drawn on [surface].
final Color onSurface; final Color onSurface;
/// A color that's clearly legible when drawn on [error].
final Color onError; final Color onError;
/// A color that's clearly legible when drawn on [background].
final Color onBackground; final Color onBackground;
/// The overall brightness of this color scheme.
final Brightness brightness; final Brightness brightness;
/// Creates a copy of this color scheme with the given fields
/// replaced by the non-null parameter values.
ColorScheme copyWith({ ColorScheme copyWith({
Color primary, Color primary,
Color primaryVariant, Color primaryVariant,
...@@ -183,6 +221,9 @@ class ColorScheme extends Diagnosticable { ...@@ -183,6 +221,9 @@ class ColorScheme extends Diagnosticable {
); );
} }
/// Linearly interpolate between two [ColorScheme] objects.
///
/// {@macro flutter.material.themeData.lerp}
static ColorScheme lerp(ColorScheme a, ColorScheme b, double t) { static ColorScheme lerp(ColorScheme a, ColorScheme b, double t) {
return ColorScheme( return ColorScheme(
primary: Color.lerp(a.primary, b.primary, t), primary: Color.lerp(a.primary, b.primary, t),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment