I'm currently developing an Android app in Flutter. How can I add a rounded button?
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.
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.
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) ) ) )
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) ) ) )
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 ) ] )
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: () {}, ),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With