Flutter upgrade to 2.5.3 causing deprecated issue in TextStyle color

423 views Asked by At

'buttonColor' is deprecated and shouldn't be used. No longer used by the framework, please remove any reference to it. This feature was deprecated after v2.3.0-0.2.pre.

Below is the code causing the issue:

enter image description here

What should I change instead of buttonColor. I tried with primary but could not find any reference in the official doc.

Thaks.

3

There are 3 answers

2
salihgueler On

Yes, there has been couple of breaking changes on buttons that you can see here --> https://docs.flutter.dev/release/breaking-changes/buttons

In your case, the themeData reference has changed, you can see a detailed information, if you check the ThemeData class.

You will be needing to use buttonTheme that is a ButtonThemeData it like the following:

Theme.of(context).buttonTheme.colorScheme?.primary
0
Rohith Nambiar On

You can use TextTheme

In your material app theme

textTheme: TextTheme(
  button: TextStyle(
     fontSize: 18.0,
     color: "Your color",
     fontWeight: FontWeight.bold
)

In your code

Text(
    style: Theme.of(context).textTheme.button
)
0
Ravindra S. Patil On

Try below code hope its help to you.

Refer Button Changes here

Refer ButtonTheme

Refer ButtonThemeData

TextButton(
  child: Text('Ok',
      style: TextStyle(
        color: Theme.of(context).buttonTheme.colorScheme?.primary,
        fontWeight: FontWeight.bold,
      )),
  onPressed: () {
    print('Button Pressed');
  },
),

your result screen-> enter image description here