I am unable to reduce the width of ElevatedButton
even though I’ve put it inside a SizedBox
.
Given below is my code:
SizedBox(
width: 70.0,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
padding:
EdgeInsets.symmetric(horizontal: 40.0, vertical: 15.0),
primary: Color(0xff78048e),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
),
child: Text(
"CLICK ME",
style: TextStyle(color: Colors.white, fontSize: 18),
),
),
),
3
Answers
you can set maximumSize property of the style which will change the size of the button
By default the minimum size of the elevated button is => Size(64, 36), use Size.zero to make button with no minimum size
Also check out the parent widget, it may forces child to take up a lot of width
You are using padding
EdgeInsets.symmetric(horizontal: 40.0, vertical: 15.0),
which is forcing the button to have a large width.Change
to
According to docs
ElevatedButton
has default minimum size ofSize(64, 36)
. You can change this by overriding theminimumSize
property insidestyle
.Example:
Output: