Skip to content

Commit

Permalink
Update ColorScheme.fromSwatch docs for Material 3 (#136816)
Browse files Browse the repository at this point in the history
part of [Clarify ColorScheme fromSwatch/fromSeed usage](flutter/flutter#132584)
  • Loading branch information
TahaTesser authored Oct 23, 2023
1 parent e869144 commit 5e8b5f4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/flutter/lib/src/material/color_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,16 @@ class ColorScheme with Diagnosticable {
_inversePrimary = inversePrimary,
_surfaceTint = surfaceTint;

/// Create a color scheme from a [MaterialColor] swatch.
/// Creates a color scheme from a [MaterialColor] swatch.
///
/// This constructor is used by [ThemeData] to create its default
/// color scheme.
/// In Material 3, this constructor is ignored by [ThemeData] when creating
/// its default color scheme. Instead, [ThemeData] uses [ ColorScheme.fromSeed]
/// to create its default color scheme. This constructor shouldn't be used
/// to update the Material 3 color scheme. It will be phased out gradually;
/// see https://github.com/flutter/flutter/issues/91772 for more details.
///
/// If [ThemeData.useMaterial3] is false, then this constructor is used by
/// [ThemeData] to create its default color scheme.
factory ColorScheme.fromSwatch({
MaterialColor primarySwatch = Colors.blue,
Color? accentColor,
Expand All @@ -467,7 +473,6 @@ class ColorScheme with Diagnosticable {
Color? errorColor,
Brightness brightness = Brightness.light,
}) {

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

0 comments on commit 5e8b5f4

Please sign in to comment.