0Day Forums
accentColor is deprecated and shouldn't be used - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: Flutter & Dart (https://0day.red/Forum-Flutter-Dart)
+--- Thread: accentColor is deprecated and shouldn't be used (/Thread-accentColor-is-deprecated-and-shouldn-39-t-be-used)



accentColor is deprecated and shouldn't be used - kristiegyvgfeags - 07-21-2023

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




RE: accentColor is deprecated and shouldn't be used - kickish21855 - 07-21-2023

As the deprecated message says:


```dart
///colorScheme.secondary
ThemeData(colorScheme: ColorScheme(secondary:Colors.white ),);
```


RE: accentColor is deprecated and shouldn't be used - Mrfayette362 - 07-21-2023

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
[![enter image description here][1]][1]

Click on **Migrate to 'ColorScheme.secondary'** it will automatically be converted.

[![enter image description here][2]][2]


[1]:

[2]:



RE: accentColor is deprecated and shouldn't be used - stirless47028 - 07-21-2023

`accentColor` is now replaced by `ColorScheme.secondary`.

* **Using new `ThemeData`:**

```dart
theme: ThemeData(
colorScheme: ColorScheme.fromSwatch().copyWith(
secondary: Colors.red, // Your accent color
),
)
```

* **Using existing `ThemeData`:**

```dart
final theme = ThemeData.dark();
```

You can use it as:

```dart
theme: theme.copyWith(
colorScheme: theme.colorScheme.copyWith(
secondary: Colors.red,
),
)
```


RE: accentColor is deprecated and shouldn't be used - amateurs725542 - 07-21-2023

Code before migration:


> Color myColor = Theme.of(context).accentColor;

Code after migration:

> Color myColor = Theme.of(context).colorScheme.secondary;


RE: accentColor is deprecated and shouldn't be used - rangy990 - 07-21-2023

Write this:

colorScheme: ColorScheme.fromSwatch()
.copyWith(secondary: kBaseAccentColor),

Then, use

> colorScheme.secondary

in place of

> accentColor

everywhere.


RE: accentColor is deprecated and shouldn't be used - attemper548702 - 07-21-2023

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: () {},
),
),