简体   繁体   English

如何在 Flutter 中将文字放在一个圆圈中

[英]How to put text in a circle in Flutter

I want to display a numerical text in a circle.我想在一个圆圈中显示一个数字文本。 I tried the following, but it looks fuzzy我尝试了以下,但它看起来很模糊

Container(child: Text(len),
decoration: BoxDecoration(
  shape: BoxShape.circle,
  border: Border.all(width: 2)))

This is how it looks.这就是它的外观。 BTW it's number 2 in a circle.顺便说一句,它是一圈的第2号。

在此处输入图像描述

If you want add spacing between the border and the Edge of the border, you can either add a Padding with EdgeInsets or reduce the fontSize of the Text如果要在边框和边框的边缘之间添加间距,可以添加带有EdgeInsetsPadding或减小TextfontSize

Visit the Flutter Docs for more information and an example. 访问 Flutter 文档以获取更多信息和示例。

Answer is somewhat obvious.答案有些明显。 Add this property to container padding: EdgeInsets.all(5)将此属性添加到容器padding: EdgeInsets.all(5)

Container(
width:40.0,
height:40.0,
child: Center(child:Text(len)),
decoration: BoxDecoration(
  shape: BoxShape.circle,
  border: Border.all(width: 2))),
CircleAvatar(
  radius: 20,
  child: Text('$value'),
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM