114

How would you make a FlatButton into a button with a rounded border? I have the rounded border shape using RoundedRectangleBorder but somehow need to color the border.

new FlatButton(
  child: new Text("Button text),
  onPressed: null,
  shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
)

Example of how button with rounded button would look : image

S.D.
  • 3,985
  • 7
  • 30
  • 57

7 Answers7

219

Use OutlinedButton instead of FlatButton.

OutlinedButton(
  onPressed: null,
  style: ButtonStyle(
    shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(30.0))),
  ),
  child: const Text("Button text"),
);
Thomas Weller
  • 49,619
  • 19
  • 114
  • 198
Rémi Rousselet
  • 216,050
  • 72
  • 473
  • 395
  • Missed a closing quote after "Button text" – Ray Li Jun 06 '18 at 18:59
  • 7
    @RemiRousselet how can i change border color? – Farhana Naaz Ansari Jan 25 '19 at 13:32
  • @Farhana in Flutter when `onPressed: null`, it means that the button is disabled, just do something with onPressed and the color will show. – Loolooii May 20 '19 at 14:41
  • `FlatButton` has the `shape` parameter as well and can have rounded corners just the same - no need to use OutlineButton. – Hasen Aug 27 '19 at 14:18
  • 3
    @Hasen Well, using the same logic we can use `MaterialButton` for everything – Rémi Rousselet Aug 27 '19 at 14:37
  • @RémiRousselet, may I ask you to have a look at a Flutter related question here : https://stackoverflow.com/questions/60565658/fluter-image-picker-package-show-images-one-after-another-with-delete-action ? – Istiaque Ahmed Mar 26 '20 at 20:49
  • 4
    @Farhana, to set the border color of an OulinedButton, use its property borderSide: BorderSide(color: Colors.blue) – egidiocs Jan 19 '21 at 00:37
  • 4
    FlatButton, RaisedButton, and OutlineButton have been replaced by TextButton, ElevatedButton, and OutlinedButton respectively. – jithin Jan 21 '21 at 06:57
  • 3
    @egidiocs I can't find borderSide property. where to set this property? – Alexa289 Jul 08 '21 at 07:47
  • with less typing, this answer https://stackoverflow.com/a/70232237/4481235 suggests using `style: OutlinedButton.styleFrom(shape, side)` then specify all available attributes if needed, which also works. – jdme Mar 25 '22 at 06:50
83
FlatButton(
          onPressed: null,
          child: Text('Button', style: TextStyle(
              color: Colors.blue
            )
          ),
          textColor: MyColor.white,
          shape: RoundedRectangleBorder(side: BorderSide(
            color: Colors.blue,
            width: 1,
            style: BorderStyle.solid
          ), borderRadius: BorderRadius.circular(50)),
        )
wizmea
  • 1,039
  • 8
  • 8
  • 11
    FlatButton, RaisedButton, and OutlineButton have been replaced by TextButton, ElevatedButton, and OutlinedButton respectively. – jithin Jan 21 '21 at 06:57
53

Use StadiumBorder shape

OutlineButton( onPressed: () {}, child: Text("Follow"), borderSide: BorderSide(color: Colors.blue), shape: StadiumBorder(), )

Kamlesh
  • 3,828
  • 30
  • 37
Ahmed
  • 1,943
  • 12
  • 15
  • 8
    For anyone who doesn't know, a StadiumBorder is a box with semi-circles on the end (like a track at a stadium, I guess) – MSpeed Feb 12 '20 at 17:52
  • You can try this also :shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)), – S.Govind Jul 01 '20 at 10:16
23
new OutlineButton(  
 child: new Text("blue outline") ,
   borderSide: BorderSide(color: Colors.blue),
  ),

// this property adds outline border color
cindy
  • 468
  • 6
  • 8
22

So I did mine with the full styling and border colors like this:

new OutlineButton(
    shape: StadiumBorder(),
    textColor: Colors.blue,
    child: Text('Button Text'),
    borderSide: BorderSide(
        color: Colors.blue, style: BorderStyle.solid, 
        width: 1),
    onPressed: () {},
)
Optimoose
  • 221
  • 2
  • 2
4

For implementing the rounded border button with a border color use this

OutlineButton(
                    child: new Text("Button Text"),borderSide: BorderSide(color: Colors.blue),
                    onPressed: null,
                    shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(20.0))
                ),
Faris Muhammed
  • 762
  • 11
  • 16
2

If you don't want to use OutlineButton and want to stick to normal RaisedButton, you can wrap your button in ClipRRect or ClipOval like:

ClipRRect(
  borderRadius: BorderRadius.circular(40),
  child: RaisedButton(
    child: Text("Button"),
    onPressed: () {},
  ),
),
CopsOnRoad
  • 175,842
  • 51
  • 533
  • 380