Change the color of ElevatedButton - flutter

How can I change the background color of the ElevatedButton?
child: ElevatedButton(
onPressed: (){},
child: Text('Get Started',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),),
),

Try using a ButtonStyle!
ElevatedButton(
onPressed: onPressed,
child: child,
style: ButtonStyle(backgroundColor: color),
)
It's also got many other options besides backgroundColor if you want to explore it.

You can do it using style as below
ElevatedButton(
onPressed: onPressed,
child: child,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black
)
)

Related

The named parameter 'color' isn't defined. flutter

body: Center(
child: TextButton(
onPressed: _handleSignIn,
child: Text('Google Sign in'),
color: Colors.amber,
),
),
);
You cant have color directly like that.
You can use style property like
child: TextButton(
onPressed: () {},
child: Text(
'Google Sign in',
style: TextStyle(
color: Colors.green,
),
),
style: ButtonStyle(
textStyle: MaterialStateProperty.all(
TextStyle(color: Colors.amber),
),
backgroundColor: MaterialStateProperty.all(Colors.amber),
),
),
Find more about ButtonStyle

How can I change the background and text color of a textbutton in flutter, in a single line?

most Easy Way to add a BackGroundColor to Textbutton
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.red),
),
BUT,
I also want to change text color:
TextButton(
style: TextButton.styleFrom(
textColor: Colors.white,
backgroundColor: Colors.red),
),
You don't need to change textColor with TextButton Style. you can do that with child widget like this:
TextButton(
style: TextButton.styleFrom(
backgroundColor: Colors.yellow,
),
onPressed: () {},
child: Text(
'click',
style: TextStyle(
color: Colors.red,
),
),
),

how to change size and text color of the elevated buttons in flutter

how to change the size and text colour of the button in this code. the left side image shows my implementation so far. I want it to be changed to the right side image buttons.
Widget lbsButton() => Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
//playSound(soundNumber);
},
child: Text('lbs'),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.deepPurple),
),
),
SizedBox(
width: 10,
),
new ElevatedButton(
onPressed: () {},
child: Text('kg'),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.deepPurple),
),
)
],
),
);
If you want to enter the styles of the specific button that is ElevatedButton and its text, it could be as follows:
SizedBox( // Change the button size
width: 100,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom( // ElevatedButton styles
primary: Colors.deepPurple,
padding: EdgeInsets.fromLTRB(20, 10, 20, 10), // Some padding example
shape: RoundedRectangleBorder( // Border
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red),
),
[...]
),
textStyle: TextStyle( // Text styles
color: Colors.white,
fontSize: 18,
overflow: TextOverflow.ellipsis,
[...]
),
onPressed: () {},
child: Text("lbs"),
),
),
Try like this
ElevatedButton(
onPressed: () {},
child: Text('kg',
style:TextStyle(color:Colors.black,fontSize:18),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.deepPurple),
),
);
You can try this also
FlatButton(
color: Colors.deepPurple[600],
child: const Text('lbs'),
textColor: Colors.white10,
onPressed: () {},
);
EDITED
Widget btn() => OutlinedButton(
child: const Text(
'lbs',
style: TextStyle(color: Colors.white),
),
style: OutlinedButton.styleFrom(
backgroundColor: Colors.deepPurple[600],
),
onPressed: () {},
);
Use ElevatedButton.styleFrom
Like so:
ElevatedButton(
style: ElevatedButton.styleFrom(
textStyle: TextStyle(color: Colors.white),
primary: Colors.purple,
shape: RoundedRectangleBorder
borderRadius: BorderRadius.circular(30),
),
),
);
Use primary to set the button color.
Use SizedBox to change the size.
Like so:
SizedBox(
width: 30,
height: 20,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
textStyle: TextStyle(color: Colors.white),
primary: Colors.purple,
),
),
)
If you want the button to take the maximum width, use:
width: double.maxFinite

Flutter Change Button Color

Any suggestions to change the color of the ElevateButton below?
child: ElevatedButton(
child: Text(
'Subscribe',
style: TextStyle(
color: gray900,
fontFamily: 'Lexend Exa',
fontSize: 20),
),
onPressed: fetchOffersMonthly,
),
Try below code hope its helpful to you. refer documentation Here for ElevatedButton
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.red,//choose your color on your need
),
child: Text(
'Subscribe',
style: TextStyle(
color: gray900,
fontFamily: 'Lexend Exa',
fontSize: 20),
),
onPressed: fetchOffersMonthly,
),
Your result screen ->
Use ButtonStyle to change the color
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.green)),
onPressed: () { },
child: Text(""),
),
ElevatedButton(
child: Text('Subscribe'),
onPressed: () {},
style: ElevatedButton.styleFrom(
primary: Colors.purple,
textStyle: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold),
),
)

How to set a Raised Button's Background Color transparent in Flutter?

Here is my code,I'd like to set a background color, transparent to my button.
I'd like to add background color to both Raised Button in my code.
I also tried wrapping it with a Container and then applying container's background transparent, but it didn't work.
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
FadeAnimation(
3.4,
SizedBox(
width: double.infinity,
height: 44,
child: RaisedButton(
color: Colors.white,
onPressed: navigateToSignUp,
child: Text(
'Sign Up',
style:
TextStyle(color: Colors.blueGrey, fontSize: 24),
),
),
),
),
SizedBox(height: 10),
FadeAnimation(
3.4,
SizedBox(
width: double.infinity,
height: 44,
child: RaisedButton(
color: Colors.white,
onPressed: navigateToSignIn,
child: Text(
'Sign In',
style: TextStyle(color: Colors.grey, fontSize: 24),
),
),
),
),
You can use Opacity with black Color
Like this :
color: Colors.black.withOpacity(0.05), //set this opacity as per your requirement
It will look much more Attractive
Just use Colors.transparent
RaisedButton(
color: Colors.transparent,
onPressed: null,
child: Text(
'Sign In',
style: TextStyle(color: Colors.grey, fontSize: 24),
),
),
Try flat button:
FlatButton(
color: Colors.transparent,
splashColor: Colors.black26,
onPressed: () {
print('done');
},
child: Text(
'Click Me!',
style: TextStyle(color: Colors.lightBlue),
),
),
Using the colors.transparent or setting opacity property to 0 may not work if you used a gradient as the background. For this reason, the most logical choice for RaisedButton is to set its elevation property to 0.
Like this:
RaisedButton(
elevation : 0, //add this line
color: Colors.white,
onPressed: navigateToSignIn,
child: Text(
'Sign In',
style: TextStyle(color: Colors.grey, fontSize: 24),
),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
elevation: 0.0,
primary: Colors.red.withOpacity(0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(2),
),
side: BorderSide(color: Colors.white)),
),
use FlatButton instead of RaisedButton as below:
new FlatButton(
child: new Icon(Icons.arrow_back_ios),
onPressed: (){}
)
RaisedButton by default either it is activer or not it will have greyish background. Try to replace FlatButton in place of that RaisedButton. Where you could simply pass color : Colors.transparent (yet FlatButton it self has a transparent background).