andyduke / styled_text_package

Text widget with formatted text using tags. Makes it easier to use formatted text in multilingual applications.
https://pub.dev/packages/styled_text
BSD 3-Clause "New" or "Revised" License
74 stars 48 forks source link

StyledText.selectable ignores newLines #62

Closed ABausG closed 1 year ago

ABausG commented 1 year ago

When using StyledText.selectable Line Breaks are not displayed.

StyledText StyledText.selectable
image image
andyduke commented 1 year ago

@ABausG Could you provide minimal code to reproduce this issue?

ABausG commented 1 year ago
Column(
        children: [
          StyledText.selectable(
            text: '''Selectable Styled text
            with <b>bold text in new line</b>''',
            tags: {
              'b': StyledTextTag(
                style: const TextStyle(fontWeight: FontWeight.bold),
              ),
            },
          ),
          StyledText(
            text: '''Non selectableStyled text
            with <b>bold text in new line</b>''',
            tags: {
              'b': StyledTextTag(
                style: const TextStyle(fontWeight: FontWeight.bold),
              ),
            },
          ),
        ],
      )

This produces:

image
andyduke commented 1 year ago

@ABausG StyledText.selectable has newLineAsBreaks set to false, unlike regular StyledText. Set newLineAsBreaks to true and the widgets will behave the same:

Column(
  children: [
    StyledText.selectable(
      newLineAsBreaks: true, // <---- !!!
      text: '''Selectable Styled text
      with <b>bold text in new line</b>''',
      tags: {
        'b': StyledTextTag(
          style: const TextStyle(fontWeight: FontWeight.bold),
        ),
      },
    ),
    StyledText(
      text: '''Non selectableStyled text
      with <b>bold text in new line</b>''',
      tags: {
        'b': StyledTextTag(
          style: const TextStyle(fontWeight: FontWeight.bold),
        ),
      },
    ),
  ],
)