Line Breaks in Long Text Flutter

前端 未结 3 1881
伪装坚强ぢ
伪装坚强ぢ 2021-02-07 05:01

How can I create line breaks within a long Text widget?

For example, I am creating a biographical page about myself. And I have three paragraphs I want to be able to dis

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-07 05:59

    I'm assuming you already have some way in the original text to tell that there should be a line break such as \n. If your paragraph is something like: var text = "paragraph1\n\nparagraph2";, you could do something like the following:

    var split = text.split('\n').map((i) {
      if (i == "") {
        return Divider();
      } else {
        return Text(i);
      }
    }).toList();
    var displayElement = Column(children: split);
    

    returning the displayElement, which will have a divider element between each paragraph.

提交回复
热议问题