Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 224
Antonin GAVREL Avatar asked Oct 26 '25 21:10

Antonin GAVREL


2 Answers

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(),
            ),
like image 161
Marek Gocał Avatar answered Oct 29 '25 07:10

Marek Gocał


You can use wordSpacing parameter

Text(
  'Build some widgets!',
  style: TextStyle(
      height: 1.2 ,
      wordSpacing: 6,
      letterSpacing: 1.0,
   )
),
like image 31
Sanjay Sharma Avatar answered Oct 29 '25 06:10

Sanjay Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!