1

I am loading a description dynamically as text, I want to design the text and insert some spacing between the text, Here is the code I am trying.

   Container(
              height: 240.h,
              width: Get.width / 1.1,
              child: SingleChildScrollView(
                child: Text(
                  product.description,
                 style: subHeadingTextStyle6,
                ),
              )),

The output of my code is like;

enter image description here

I want the following spacing of the text

enter image description here

1
  • are you used wordSpacing style? Commented Nov 1, 2021 at 10:19

2 Answers 2

1
 Text( product.description, style: TextStyle(color: Colors.black, height: 4)),

Update to comment: "thanks for your concern, the height property is good, but it did it equally for all line, what else I have to do to look like the picture, which I have shared in question"

This will do the job!

RichText(
        text: TextSpan(
        children: splitText(text),
              ),
            )

List<TextSpan> splitText(String text) {
  List<TextSpan> reasonList = [];
  text.split(".").forEach((element) {
    reasonList.add(TextSpan(
        text: "$element\n\n\n", style: TextStyle(color: Colors.black)));
  });
  return reasonList;
}

So what are we doing exactly?

First we're turning your text into a list of sentences, with text.split(".") which splits the text whenever it encounters a '.'

Now we are adding it in a list of TextSpan to be able to use it in RichText. Here's the part where it makes space between every sentence "$element\n\n\n" I don't know if you know but \n means insert a new line. As if you hit the enter button. I used 3 \n's so that it will leave 2 lines empty after every sentence.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your concern, the height property is good, but it did it equally for all line, what else I have to do to look like the picture, which i have shared in question
Awesome, please mark this answer as accepted by clicking on the green tick below the upvotes. Happy coding :)
0

I think just adding \n\n between the paragraphs should work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.