Search code examples
flutterdartcolor-scheme

flutter ColorScheme problem with some deprecated warnings


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?


Solution

  • 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),
        );