I can do the following to have a TextField with rounded edges in Flutter.
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30.0),
),
),
)
The edges are now rounded, but not sure whether they are perfect semi-circle.
How can I have the edges with perfect semi-circle?
(I guess I have to adjust the radius provided in the code, but how to find the exact radius to provide?)
4
Answers
To achieve a perfect semicircle, you can follow this method
Find the height of the
TextField
. Default height is 48px (whenisDense == false
).radius >= height/2
. For any radius value greater than half of the TextField height, you will get perfect semicircle edges. So, give any value greater than or equal to 24.The default height of
TextField
is 48. So you can useborderRadius: BorderRadius.circular(48 / 2),
. But there is default padding you need to count,EdgeInsets.fromLTRB(12, 8, 12, 8)
or12
if the dense is true. So the perfect semi-circle can be seenYou can create custom border by extending the
OutlineInputBorder