Reputation: 1344
The new version of Flutter (from 2.5 onwards) has deprecated the accentColor property within ThemeData and now must be handled from colorScheme as a secondary color colorScheme: ColorScheme.fromSwatch().copyWith (secondary: newColorForAccent))
,
Such as I can view, it is not enough since accentColor was also used in Flutter to define the color of other widgets such as CheckBoxTile and SwitchListTile.
The ThemeData that I have in main is as follows:
theme: ThemeData(
primaryColor: Color (0xFF4BD1FF),
colorScheme: ColorScheme.fromSwatch().copyWith(secondary: Color (0xFFD8A21B)),
//textTheme and others
),
How can I redefine the color of these widgets so that it can be used throughout the App?
Upvotes: 0
Views: 828
Reputation: 1344
I found the solution with a bit of trial and error. I leave it here in case it is useful to someone. Basically what is required is to define the themes for each component inside ThemeData. Here's an example:
checkboxTheme: CheckboxThemeData(
checkColor: MaterialStateProperty.all(Colors.white),
fillColor: MaterialStateProperty.all(Color (0xFFD8A21B))
),
switchTheme: SwitchThemeData(
thumbColor: MaterialStateProperty.all(Color (0xFFD8A21B)),
trackColor: MaterialStateProperty.all(Color (0x66D8A21B)),
),
radioTheme: RadioThemeData(
fillColor: MaterialStateProperty.all(Color (0xFFD8A21B))
),
Since this is part of the main, don't forget to always do a Full Restart after implementing. The Flutter Hot reload will not display any changes in this case.
Upvotes: 3