1

I have a string which contains text with multiple \n, I want to display that text in the new line but with a leading icon.

For e.g, If I have a String str="Hello\nThere\nUser". I want to display the text like this:

Icon  Hello
Icon  There
Icon  User

How can I achieve this?

1 Answer 1

4
    String str = "Hello\nThere\nUser";
    List<String> list = str.split('\n');
    list.forEach((s) {
      widgetList.add(Row(
        children: <Widget>[
          Icon(Icons.directions_car),
          Text(s),
        ],
      ));
    });

    return Column(children: widgetList);

or

    String str = "Hello\nThere\nUser";
    return Column(
      children: [
        for (var s in str.split('\n'))
          Row(
            children: <Widget>[
              Icon(Icons.directions_run),
              Text(s),
            ],
          )
      ],
    );
Sign up to request clarification or add additional context in comments.

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.