Question

accentColor is deprecated and shouldn't be used

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
 48  40861  48
1 Jan 1970

Solution

 55

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

2021-09-23

Solution

 38

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,
      ),
    )
    
2021-09-25