flutterdart

The argument type 'MaterialColor' can't be assigned to the parameter type 'MaterialStateProperty<Color>


I have a question related with the new ElevatedButtonThemeData widget, basically I want to set the background color for all ElevatedButtons in my app, I'm struggling trying to set it up in the ThemeData definition by doing:

      theme: ThemeData(
        ...
        elevatedButtonTheme: ElevatedButtonThemeData(
            style: ButtonStyle(backgroundColor: Colors.red)), // Here Im having the error
        ...
        ),
      ),

Error:

The argument type 'MaterialColor' can't be assigned to the parameter type 'MaterialStateProperty<Color?>?'.dartargument_type_not_assignable)

Solution

  • After reading the documentation I found the way to set the color.

      theme: ThemeData(
        ...
        elevatedButtonTheme: ElevatedButtonThemeData(
            style: ButtonStyle(backgroundColor: MaterialStateProperty.all<Color>(Colors.red))), // Here Im having the error
        ...
        ),
      ),