maddy
maddy

Reputation: 4111

Flutter upgrade to 2.5.3 causing deprecated issue in TextStyle color

'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.

Upvotes: 0

Views: 529

Answers (3)

Ravindra S. Patil
Ravindra S. Patil

Reputation: 14885

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

Upvotes: 0

salihgueler
salihgueler

Reputation: 3632

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

Upvotes: 0

Rohith Nambiar
Rohith Nambiar

Reputation: 3720

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
)

Upvotes: 0

Related Questions