首页 > 解决方案 > Flutter:如何增加文本中标签“\ t”的缩进宽度

问题描述

我有以下用于打印文本的小部件:

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 缩进太小。有没有办法增加缩进以占用更多空间?

标签: fluttertextfield

解决方案


如果您仍然想保留单词之间的空格,并且只增加选项卡,您可以使用 Wrap 小部件

            Wrap(
              children: "hello hello\tworld\t42"
                  .split("\t")
                  .map((text) => Text(text))
                  .expand((element) => [
                        element,
                        SizedBox(
                          width: 50,
                        )
                      ])
                  .toList()
                    ..removeLast(),
            ),

推荐阅读