Home > other >  color property for ElevatedButton Widget throws an error
color property for ElevatedButton Widget throws an error

Time:02-21

Here's my code:

color is underined red.

body: Row(
        children: <Widget>[
          Text('Hi Mom!'),
          ElevatedButton(
              onPressed: () {  },
              color: Colors.deepPurple,
              child: Text('Hi Dad!'),
          ),
        ],
      ),

It shows the error:

The named parameter 'color' isn't defined.

I also did flutter clean and Invalidate Caches and Restart, doesn't seem to work.

flutter --version:

Flutter 2.10.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision db747aa133 (11 days ago) • 2022-02-09 13:57:35 -0600
Engine • revision ab46186b24
Tools • Dart 2.16.1 • DevTools 2.9.2

CodePudding user response:

Try below code hope its help to you. Refer ElevatedButton enter image description here

CodePudding user response:

Use this: MaterialStateProperty

The purpose of MaterialStateProperty is to make it possible to specify different styles for different states i.e.,

        TextButton(
            style: ButtonStyle(
                overlayColor: MaterialStateProperty.all(Colors.redAccent),
                shape: MaterialStateProperty.all(RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(12.0))),
                backgroundColor:
                    MaterialStateProperty.all(Colors.deepOrangeAccent)),
            onPressed: () {
            //
            },
            child: const Text(
              'Hiii',
              style: TextStyle(color: Colors.white),
            ))
  • Related