Search code examples
fluttertextfield

Flutter : How to increase indentation width of tab '\t' in text


I have the following widget that I use to print 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)));
  }
}

But if I use it like:

NormalText('hello\tworld\t42')

The \t indentation is too tiny. Is there any way to increase the indentation to take more space ?


Solution

  • If you still want to keep the space between the words, and only increase the tabs, you can use Wrap widget

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