Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a rounded button / button with border-radius in Flutter

Tags:

flutter

dart

I'm currently developing an Android app in Flutter. How can I add a rounded button?

like image 590
Kingsley CA Avatar asked Apr 23 '18 23:04

Kingsley CA


People also ask

How do you make button border rounded in Flutter?

In Flutter, the Container() widget is used for styling your widget. Using the Container() widget, you can set a border or rounded corner of any widget. If you want to set any type of styling and set the decoration, put that widget into the Container() widget. That provides many properties to the decoration.

How do you give a border to the radius in Flutter?

horizontal widget the left property is holding Radius. circular(15), which gives the left side of the border (i.e. the top-left and bottom,-left) a radius of 15 pixels and the right property is holding Radius. circular(30), which in turn gives the right portion of the border a radius of 30 pixels.


2 Answers

1. Solution Summary

FlatButton and RaisedButton are deprecated.

So, you can use shape which placed in the style property, for TextButton and ElevatedButton.

There are some changes since Flutter 2.0:

  • style: the property type has changed to ButtonStyle
  • shape: the property type has changed to MaterialStateProperty<T>

2. Rounded Button

Inside the style property exists the shape property:

style: ButtonStyle(   shape: MaterialStateProperty.all<RoundedRectangleBorder>(     RoundedRectangleBorder(       borderRadius: BorderRadius.circular(18.0),       side: BorderSide(color: Colors.red)     )   ) ) 

Enter image description here

Square Button

For a square button you can use ElevatedButton or otherwise add:

style: ButtonStyle(   shape: MaterialStateProperty.all<RoundedRectangleBorder>(     RoundedRectangleBorder(       borderRadius: BorderRadius.zero,       side: BorderSide(color: Colors.red)     )   ) ) 

Enter image description here

Complete Example

Row(   mainAxisAlignment: MainAxisAlignment.end,   children: [     TextButton(       child: Text(         "Add to cart".toUpperCase(),         style: TextStyle(fontSize: 14)       ),       style: ButtonStyle(         padding: MaterialStateProperty.all<EdgeInsets>(EdgeInsets.all(15)),         foregroundColor: MaterialStateProperty.all<Color>(Colors.red),         shape: MaterialStateProperty.all<RoundedRectangleBorder>(           RoundedRectangleBorder(             borderRadius: BorderRadius.circular(18.0),             side: BorderSide(color: Colors.red)           )         )       ),       onPressed: () => null     ),     SizedBox(width: 10),     ElevatedButton(       child: Text(         "Buy now".toUpperCase(),         style: TextStyle(fontSize: 14)       ),       style: ButtonStyle(         foregroundColor: MaterialStateProperty.all<Color>(Colors.white),         backgroundColor: MaterialStateProperty.all<Color>(Colors.red),         shape: MaterialStateProperty.all<RoundedRectangleBorder>(           RoundedRectangleBorder(             borderRadius: BorderRadius.zero,             side: BorderSide(color: Colors.red)           )         )       ),       onPressed: () => null     )   ] )  
like image 79
Abror Esonaliev Avatar answered Oct 24 '22 11:10

Abror Esonaliev


You can use the ElevatedButton Widget. The elevated button widget has a shape property which you can use as shown in the below snippet.

ElevatedButton(       style: ButtonStyle(           shape: MaterialStateProperty.all<RoundedRectangleBorder>(               RoundedRectangleBorder(                   borderRadius: BorderRadius.circular(18.0),                   side: BorderSide(                       color: Colors.teal,                        width: 2.0,                   ),               ),           ),       ),       child: Text('Submit'),       onPressed: () {}, ), 
like image 20
Dhrumil Shah - dhuma1981 Avatar answered Oct 24 '22 12:10

Dhrumil Shah - dhuma1981