Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accentColor is deprecated and shouldn't be used

Tags:

flutter

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
like image 454
rozerro Avatar asked Sep 22 '21 17:09

rozerro


People also ask

What can I use instead of accentColor?

accentColor is now replaced by ColorScheme. secondary .

What can I use instead of accentColor in flutter?

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 accentColor?

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.

Is accent color deprecated in Dart?

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.

What happened to the themedata accentcolor property in Material Design?

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.

What is the “accent” color for material components?

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.

What is the difference between accent color and onsecondary color in colorscheme?

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.


Video Answer


5 Answers

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 enter image description here

Click on Migrate to 'ColorScheme.secondary' it will automatically be converted.

enter image description here

like image 174
kamran khan Avatar answered Nov 11 '22 15:11

kamran khan


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,
      ),
    )
    
like image 32
CopsOnRoad Avatar answered Nov 11 '22 15:11

CopsOnRoad


As the deprecated message says:

///colorScheme.secondary
 ThemeData(colorScheme: ColorScheme(secondary:Colors.white ),);
like image 40
Nicolás López Avatar answered Nov 11 '22 14:11

Nicolás López


Code before migration:

Color myColor = Theme.of(context).accentColor;

Code after migration:

Color myColor = Theme.of(context).colorScheme.secondary;

like image 34
benten Avatar answered Nov 11 '22 15:11

benten


Write this:

colorScheme: ColorScheme.fromSwatch()
            .copyWith(secondary: kBaseAccentColor),

Then, use

colorScheme.secondary

in place of

accentColor

everywhere.

like image 39
Mohammad Bilal Akbar Avatar answered Nov 11 '22 15:11

Mohammad Bilal Akbar