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

Viewed 2483

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 ?

3 Answers

You can use wordSpacing parameter

Text(
  'Build some widgets!',
  style: TextStyle(
      height: 1.2 ,
      wordSpacing: 6,
      letterSpacing: 1.0,
   )
),

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(),
            ),

You can combine the \t to get more Tab Spaces.

Check the code below for an example on how to do that :

// combine two \t
print('hello\t\tworld\t42');
Related