Otis
Otis

Reputation: 401

Flutter foregroundColor property is throwing error in my project

I am using flutter version 3.0.0

I am having a TextButton, but I get an error on the foregroundColor property showing, The named parameter 'foregroundColor' isn't defined. I also tried uisng flutter 3.3.3, but still get the same error.

Image

TextButton(
  style: TextButton.styleFrom(
  foregroundColor: Colors.white,
  backgroundColor: Theme.of(context).colorScheme.secondary,
  ),
)

Upvotes: 1

Views: 614

Answers (1)

Ozan Taskiran
Ozan Taskiran

Reputation: 3552

Use the MaterialStateProperty in the Flutter 3+ versions

 textButtonTheme: TextButtonThemeData(
      style: ButtonStyle(
        foregroundColor: MaterialStateProperty.all<Color>(Colors.whtie,), 
      ),
    ),

See also https://docs.flutter.dev/release/breaking-changes/buttons

Upvotes: 4

Related Questions