I cannot work out why this text is not centering inside the button:
SizedBox(
width: 30,
height: 30,
child: ElevatedButton(
onPressed: () {
FavourDown();
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black, // background color
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20), // button's shape
),
),
child: const Text(
'-',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
),
),
),
),
Result:
2
Answers
Elevated button is a fixed component, you can’t customise it to your own sizes. (You could just set padding to EdgeInsets.zero in style of elevated button)
Better to use a Container and decoration to make your own button and Use the Centre() widget to centre the text in the container of your preference.
Here is an example :
Hope this helped
Please use this code to center text.