skip to Main Content

I had some deprecated warnings in Theme . the code before :

class myTheme {
static getTheme() => ThemeData(

  primaryColor: Colors.grey,
  primarySwatch: Colors.grey,
  backgroundColor: Colors.white,
  buttonColor:Colors.blueAccent,
  accentColor: Colors.blueGrey,
);
}

accentColor and buttonColor were deprecated so I changed it to :

class RevoCheckTheme {
 static getTheme() => ThemeData(

  primaryColor: Colors.grey,
  backgroundColor: Colors.white,
  colorScheme:
  ColorScheme.fromSwatch(primarySwatch: Colors.grey)
      .copyWith(secondary: Colors.blueGrey)
      .copyWith(surface:Colors.blueAccent)
);
}

and now the the colors aren’t the same as before , I think primarySwatch effects on other colors maybe . is it the right way to solve it or Im completely wrong?

2

Answers


  1. It will be

    static getTheme() => ThemeData(
          primaryColor: Colors.grey,
          // backgroundColor: Colors.white,
          colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.grey)
              .copyWith(
                  secondary: Colors.blueGrey,
                  background: Colors.white,
                  surface: Colors.blueAccent),
        );
    
    Login or Signup to reply.
  2. You should edit it to

    static getTheme() => ThemeData(
      primaryColor: Colors.grey,
      // backgroundColor: Colors.white,
      colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.grey)
          .copyWith(
              secondary: Colors.blueGrey,
              background: Colors.white,
              surface: Colors.blueAccent),
    );
    
    • this will copy the old values for the required arguments of colorScheme and override the values you want (secondary, surface…)
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search