[英]Flutter : How to increase indentation width of tab '\t' in text
我有以下用於打印文本的小部件:
class NormalText extends StatelessWidget {
final String txt;
NormalText(this.txt) {}
@override
Widget build(BuildContext context) {
return Container(
child: Text(txt,
style: TextStyle(
color: Colors.grey,
fontSize: 20,
fontWeight: FontWeight.bold)));
}
}
但如果我像這樣使用它:
NormalText('hello\tworld\t42')
\t 縮進太小了。 有沒有辦法增加縮進以占用更多空間?
您可以使用wordSpacing
參數
Text(
'Build some widgets!',
style: TextStyle(
height: 1.2 ,
wordSpacing: 6,
letterSpacing: 1.0,
)
),
如果你仍然想保留單詞之間的空間,並且只增加標簽,你可以使用 Wrap 小部件
Wrap(
children: "hello hello\tworld\t42"
.split("\t")
.map((text) => Text(text))
.expand((element) => [
element,
SizedBox(
width: 50,
)
])
.toList()
..removeLast(),
),
您可以組合\t
以獲得更多Tab Spaces
。
檢查下面的代碼以獲取有關如何執行此操作的示例:
// combine two \t
print('hello\t\tworld\t42');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.