Create A Rounded Button / Button With Border-radius In Flutter


Answer :

1. Solution Summary


You can use shape for FlatButton and RaisedButton.


2. Rounded Button


shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)
),

enter image description here


Square Button


shape: RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
side: BorderSide(color: Colors.red)
),

enter image description here


Complete Example


Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)),
color: Colors.white,
textColor: Colors.red,
padding: EdgeInsets.all(8.0),
onPressed: () {},
child: Text(
"Add to Cart".toUpperCase(),
style: TextStyle(
fontSize: 14.0,
),
),
),
SizedBox(width: 10),
RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)),
onPressed: () {},
color: Colors.red,
textColor: Colors.white,
child: Text("Buy now".toUpperCase(),
style: TextStyle(fontSize: 14)),
),
],
)


You can use the RaisedButton Widget. Raised Button Widget has shape property which you can utilise as shown in below snippet.



 RaisedButton(
child: Text("Press Me"),
onPressed: null,
shape: RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
)


enter image description here



There are many ways of doing it. I am listing few here.



(1) Using RoundedRectangleBorder



RaisedButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
onPressed: () {},
child: Text("Button"),
)


(2) Using ClipRRect



ClipRRect(
borderRadius: BorderRadius.circular(40),
child: RaisedButton(
onPressed: () {},
child: Text("Button"),
),
)


(3) Using ClipOval



ClipOval(
child: RaisedButton(
onPressed: () {},
child: Text("Button"),
),
)


(4) Using ButtonTheme



ButtonTheme(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
child: RaisedButton(
onPressed: () {},
child: Text("Button"),
),
)


(5) Using StadiumBorder



RaisedButton(
shape: StadiumBorder(),
onPressed: () {},
child: Text("Button"),
)


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable