Reputation: 7146
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
Upvotes: 48
Views: 42678
Reputation: 11
you need to add a color scheme because accent color is deprecated.
body: const Center(child: const Text('BMI Calculator')),
floatingActionButton: Theme(
data: ThemeData(
colorScheme:
ColorScheme.fromSwatch().copyWith(secondary: Colors.white),
),
child: FloatingActionButton(
child: const Icon(
Icons.add,
),
onPressed: () {},
),
),
Upvotes: 1
Reputation: 170
Write this:
colorScheme: ColorScheme.fromSwatch()
.copyWith(secondary: kBaseAccentColor),
Then, use
colorScheme.secondary
in place of
accentColor
everywhere.
Upvotes: 5
Reputation: 790
Code before migration:
Color myColor = Theme.of(context).accentColor;
Code after migration:
Color myColor = Theme.of(context).colorScheme.secondary;
Upvotes: 5
Reputation: 267454
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,
),
)
Upvotes: 39
Reputation: 822
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
Click on Migrate to 'ColorScheme.secondary' it will automatically be converted.
Upvotes: 55
Reputation: 510
As the deprecated message says:
///colorScheme.secondary
ThemeData(colorScheme: ColorScheme(secondary:Colors.white ),);
Upvotes: 3