The accentColor
in ThemeData
was deprecated.
What to use then in ThemeData
?
theme: ThemeData(
brightness: Brightness.light,
primaryColor: kBaseColor,
accentColor: kBaseAccentColor, // 'accentColor' is deprecated and shouldn't be used
accentColor is now replaced by ColorScheme. secondary .
The ColorScheme 's secondary color is now typically used instead of accentColor and the onSecondary color is used when a contrasting color is needed.
What Is an Accent Color? Accent colors are supplementary colors that typically contrast or complement the primary colors used in a room. Accent colors are used for emphasis, to enhance a color scheme, or to liven up or add drama to an otherwise monochromatic space.
info • 'accentColor' is deprecated and shouldn't be used. Use colorScheme.secondary instead. This feature was deprecated after v2.3.0-0.1.pre. • lib/app.dart:32:9 • deprecated_member_use info • 'accentColor' is deprecated and shouldn't be used.
The ThemeData accentColor, accentColorBrightness, accentIconTheme and accentTextTheme properties have been deprecated. The Material Design spec no longer specifies or uses an “accent” color for the Material components. The default values for component colors are derived from the overall theme’s color scheme.
The Material Design spec no longer specifies or uses an “accent” color for the Material components. The default values for component colors are derived from the overall theme’s color scheme.
The ColorScheme ’s secondary color is now typically used instead of accentColor and the onSecondary color is used when a contrasting color is needed. This was a small part of the Material Theme System Updates project.
Use the below code instead of accentColor: kBaseAccentColor,
colorScheme: ColorScheme.fromSwatch()
.copyWith(secondary: kBaseAccentColor),
OR
Do this in a simple way: Click on Magic Bulb
Click on Migrate to 'ColorScheme.secondary' it will automatically be converted.
accentColor
is now replaced by ColorScheme.secondary
.
Using new ThemeData
:
theme: ThemeData(
colorScheme: ColorScheme.fromSwatch().copyWith(
secondary: Colors.red, // Your accent color
),
)
Using existing ThemeData
:
final theme = ThemeData.dark();
You can use it as:
theme: theme.copyWith(
colorScheme: theme.colorScheme.copyWith(
secondary: Colors.red,
),
)
As the deprecated message says:
///colorScheme.secondary
ThemeData(colorScheme: ColorScheme(secondary:Colors.white ),);
Code before migration:
Color myColor = Theme.of(context).accentColor;
Code after migration:
Color myColor = Theme.of(context).colorScheme.secondary;
Write this:
colorScheme: ColorScheme.fromSwatch()
.copyWith(secondary: kBaseAccentColor),
Then, use
colorScheme.secondary
in place of
accentColor
everywhere.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With