Flutter Change Button Color - flutter

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),
),
)

Related

How can I give my text a background color?

I want to give color to the text background like the picture below:
while mine is still like this:
And the code that I have written is like this:
Text(
'Last Activity',
style: TextStyle(
fontSize: 16,
color: ColorName.whitePrimary,
),
),
body: Center(
child: TextButton.icon(
style: TextButton.styleFrom(
textStyle: TextStyle(color: Colors.blue),
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
onPressed: () => {},
icon: Text('Last Activity'),
label: Icon(Icons.chevron_right),
),
),
Set the style parameter in your Text widget:
Text(
'Hello, World!',
style: TextStyle(fontSize: 32, backgroundColor: Colors.green),
);
See also
TextStyle (flutter.dev)
Try the following code:
Text(
'Last Activity',
style: TextStyle(
fontSize: 16,
color: ColorName.whitePrimary,
backgroundColor: Colors.indigo[400],
),
),
Refer below code hope its help to you, I have try 2 ways TextButton.icon and Row
1. Using TextButton Widget
TextButton.icon(
style: TextButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: const Color.fromRGBO(60, 75, 175, 1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6.0),
),
),
onPressed: () => {},
icon: const Text('Last Activity'),
label: const Icon(Icons.chevron_right),
),
Result Using TextButton.icon->
2. Using Row
GestureDetector(
onTap: () {},
child: Container(
height: 30,//change on your need
width: 120,//change on your need
padding: const EdgeInsets.all(5),
alignment: Alignment.center,
color: const Color.fromRGBO(60, 75, 175, 1),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: const [
Text(
'Last Activity',
style: TextStyle(
color: Colors.white,
),
),
Icon(
Icons.chevron_right,
color: Colors.white,
),
],
),
),
),
Result Using Row->
Try the following code:
Text(
'Last Activity',
style: TextStyle(
fontSize: 16,
color: ColorName.whitePrimary,
),
),

Change the color of ElevatedButton

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
)
)

Text Button in flutter

I'm new to flutter want to create below send again text as a button. How can I do that? appreciate your help on this.
Align(
alignment: Alignment.bottomLeft,
child: Text(
'send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)
)
)
You can use the TextButton widget for this
TextButton(
style: TextButton.styleFrom(
TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
),
),
onPressed: () {},
child: const Text('Send again'),
or you can just wrap your Text widget with gestureDetector
Align(
alignment: Alignment.bottomLeft,
child: GestureDetector(
onTap: () {}
Text(
'send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)
))
)
Align(
alignment: Alignment.bottomLeft,
child: InkWell(
onTap: () {
// add action here whatever you want.
},
child: Text('send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)
),
)
)
In Flutter almost everything is a Widget. That means even a gesture detector is a widget.
Knowing that, and being able to create a Text widget you are half way there to your destination. You need to just wrap your Text widget with a TextButton that expects its child property to be a Widget and you could provide your Text widget as the child of the TextButton.
Here is the documentation for TextButton and that even includes a very good video on how to use TextButtons in Flutter.
This might work ,
TextButton(
child: Text('send again'),
style: TextButton.styleFrom(
primary: Colors.teal,
onPrimary: Colors.white,
textStyle: TextStyle(
color: Colors.black,
fontSize: 40,
fontStyle: FontStyle.italic
),
),
onPressed: () {
print('Pressed');
},
)
You can use buttons available in flutter like MaterialButton, TextButton, ElevatedButton, etc. or you can use InkWell or GestureDetector
Align(
alignment: Alignment.bottomLeft,
child: GestureDetector(
onTap: () {},
child: Text('send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)),
))
Or
Align(
alignment: Alignment.bottomLeft,
child: InkWell(
onTap: () {},
child: Text('send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)),
))
Or
Align(
alignment: Alignment.bottomLeft,
child: MaterialButton(
onPressed: (){},
child: Text('send again ',
style: TextStyle(
height: 1.2,
fontFamily: 'Dubai',
fontSize: 13,
color: Colors.blue,
fontWeight: FontWeight.w500,
)),
))

OutlinedButton exception when trying to set max size

I'm trying to create something like the below image:
I used two OutlinedButton in a row:
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
OutlinedButton(
child: const Icon(
Icons.arrow_back,
color: colorBackButton,
),
style: ButtonStyle(
fixedSize: MaterialStateProperty.resolveWith(
(states) => Size(65.0, 65.0)))),
Padding(padding: EdgeInsets.only(left: 14.0)),
OutlinedButton(
child: Text(
'Next',
style: GoogleFonts.inter(
textStyle: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white)),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.resolveWith((states) {
return colorPrimaryButton;
}),
}),
])
This has led me to this result:
I tried to wrap the Next button with Sizedbox.expand and also add a minimumSize to the button style:
minimumSize: MaterialStateProperty.resolveWith((states) => const Size.fromHeight(55.0))
Both results with a BoxConstraints forces an infinite width. These invalid constraints were provided to RenderPhysicalShape's layout() function by t
Digging into the exception, it's written:
The offending constraints were: BoxConstraints(w=Infinity, 55.0<=h<=Infinity)
How can I make the Next button fill the entire row's space (discluding the padding of course)?
You can wrap with Expanded widget to get maximum available space.
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
OutlinedButton(
onPressed: () {},
child: const Icon(
Icons.arrow_back,
color: Colors.amber,
),
style: ButtonStyle(
fixedSize: MaterialStateProperty.resolveWith(
(states) => const Size(65.0, 65.0),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 14.0),
child: OutlinedButton(
onPressed: () {},
child: const Text('Next',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white)),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.deepPurple),
fixedSize: MaterialStateProperty.resolveWith(
(states) => const Size(65.0, 65.0),
),
),
),
),
),
],
);
You can play with padding. Also, you can use LayoutBuilder.
try use expanded widget Wrap next button with expanded like that
Expanded(
child: OutlinedButton(
child: Text(
'Next',
style: GoogleFonts.inter(
textStyle: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white)),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.resolveWith((states) {
return colorPrimaryButton;
}),
}),
),

Overflowed with some Row of raisedbuton in flutter

Hello I only try to create circular button for each days of the week. For this I used Raisedbutton and CircleBorder shape, but when I have more than 4 raisedbutton, I have an overflowed, as if there was a padding hidden in the raisedbutton...
new Row (
children: <Widget>[
RaisedButton(
hoverElevation:5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"), style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 15.0)),
onPressed: ()
{
},
shape: new CircleBorder(
)
),
RaisedButton(),
RaisedButton(),
RaisedButton(),
RaisedButton....
]
)
For one line you can use SingleChildScrollView widget for scrolling
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(children: <Widget>[
RaisedButton(
hoverElevation: 5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 15.0)),
onPressed: () {},
shape: new CircleBorder()),
RaisedButton(
hoverElevation: 5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 15.0)),
onPressed: () {},
shape: new CircleBorder()),
RaisedButton(),
RaisedButton(),
RaisedButton(),
RaisedButton(),
]),
)
or You just have to use Wrap widget for multi line
Wrap(
spacing: 2.0, // gap between adjacent chips
runSpacing: 2.0, // gap between lines
children: <Widget>[
RaisedButton(
hoverElevation: 5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 15.0)),
onPressed: () {},
shape: new CircleBorder()),
RaisedButton(
hoverElevation: 5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 15.0)),
onPressed: () {},
shape: new CircleBorder()),
RaisedButton(
hoverElevation: 5,
textColor: Colors.black,
color: Colors.white,
child: Text(("Lu"),
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w600,
fontSize: 15.0)),
onPressed: () {},
shape: new CircleBorder()),
RaisedButton(),
RaisedButton(),
RaisedButton(),
RaisedButton(),
])
I found this solution
I can custom the padding with this solution
new Row (
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Material(
borderRadius: BorderRadius.circular(30.0),
shadowColor: Colors.white,
child: InkWell
(
onTap:() { setState(() {
change=1;
swiper1(); }
);
},
child: Padding(
padding: const EdgeInsets.all(12.0),
child : Text(("Lu"), style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 15.0)),
)
)
),
Material(
borderRadius: BorderRadius.circular(30.0),
shadowColor: Colors.white,
child: InkWell
(
onTap:() { setState(() {
change=2;
swiper1(); }
);
},
child: Padding(
padding: const EdgeInsets.all(12.0),
child : Text(("Ma"), style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 15.0)),
)
)
),
....