7

I have created two buttons in a row using flutter. now I want to change border-radius o=f buttons. how can I do this properly? the picture shows the buttons I was created.

enter image description here

Widget lbsButton() => Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          SizedBox(
            width: 80,
            height:50,
            child: ElevatedButton(
              onPressed: () {},
              child: Text('lbs'),
              style: ButtonStyle(
                
                backgroundColor: MaterialStateProperty.all<Color>(mainPurpleText),

              ),
              
            ),
          ),
          SizedBox(
            width: 10,
          ),
          SizedBox(
            width: 80,
            height:50,
            child: new ElevatedButton(
              onPressed: () {},
              child: Text('kg' , style:TextStyle(color:Colors.grey,fontSize:13),
              ),
              style: ButtonStyle(
                backgroundColor: MaterialStateProperty.all<Color>( Colors.white),
              ),
            ),
          )
        ],
      ),
    );
  • I should note that using style on the widget is somewhat like using style in html tags. Similarly to the html recommendation of using CSS classes instead of style, in flutter you should prefer to use Themes and custom Widgets instead of styling individual widgets. – LFLFM Apr 22 '22 at 07:16

4 Answers4

6
return ElevatedButton(
      onPressed: onPressed,
      child: Text('test'),
      style: ButtonStyle(
        shape: MaterialStateProperty.all(
          RoundedRectangleBorder(
            // Change your radius here
            borderRadius: BorderRadius.circular(16),
          ),
        ),
      ),
    );
Stijn2210
  • 812
  • 6
  • 14
  • thanks but when I add all these changes to my first button, as per the code my second button code became red. what should I do? buttons are in same row one after the other –  Jan 26 '22 at 13:31
4

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

ElevatedButton(
      style: ButtonStyle(
          backgroundColor: MaterialStateProperty.all<Color>(mainPurpleText),
          shape: MaterialStateProperty.all<RoundedRectangleBorder>(
              RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(20.0),
              ),
          ),
      ),
      child: Text('Submit'),
      onPressed: () {},
),
reza
  • 1,354
  • 1
  • 7
  • 25
1

You can apply ElevatedButton.stylefrom() on the "style" property of ElevatedButton.

ElevatedButton(       
      style: ElevatedButton.styleFrom(
         shape: RoundedRectangleBorder(
         borderRadius: BorderRadius.circular(40),
             ),
           ),
      onPressed: () {},
      child: Text('kg'),
    )
Sami
  • 96
  • 9
0

You can use ButtonStyle and I think it is kind of similar Create a rounded button / button with border-radius in Flutter.

style: ButtonStyle(
  shape: MaterialStateProperty.all<RoundedRectangleBorder>(
      RoundedRectangleBorder(
    borderRadius:
        BorderRadius.circular(18.0), // radius you want
    side: BorderSide(
      color: Colors.transparent, //color
    ),
  )),

enter image description here

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56