Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single number as HighlightedWord causes error #19

Closed
SRomanova opened this issue Oct 22, 2021 · 3 comments
Closed

Single number as HighlightedWord causes error #19

SRomanova opened this issue Oct 22, 2021 · 3 comments

Comments

@SRomanova
Copy link

This is a very useful package. Thank you for creating it!
I faced some issues in my work with it and I found work around, but since it might be useful for other users, I decided to document it.
To present overview of evaluation, I need to replace some substrings in a template message and to print them out with additional styling. For this task I use combination of ARB file and this package. All values are loading from API and I may receive null for some of them. Here are two issues I faced in my work:

  1. with nullable keys:
    I save nullable variables like this
    final value = data?.toString() ?? '';
    and it doesn't return compile error, but causes an ugly result.
    Fix this with adding it with if statement - if(data != null) template: HighlightedWord(textStyle:...),

  2. with single numbers:
    If some of keys is number (like 0) it replaces substrings, witch have their own different key.
    Example: "0's points didn't change. Current number of points is 0. 0 has changed technical seniority to Intern."
    where replaced values are bold and instead of userName: HighlightedWord(textStyle:...), for customizing that value is used score: HighlightedWord(textStyle:...) where score = scoreValue.toString() and scoreValue = 0
    Fix this with with adding empty space in front of the number character like this: score = ' ${scoreValue.toString()}'

Hopefully this information will be useful to others. And again: Thank you for creating this package!

@SRomanova SRomanova changed the title Single number as HighlightedWord cause error Single number as HighlightedWord causes error Oct 22, 2021
@desconexo desconexo assigned desconexo and unassigned desconexo Jan 12, 2022
@desconexo desconexo pinned this issue Jan 13, 2022
@AdarshaBista
Copy link

I was also having issues when the first word of the text was a number and was highlighted. In my case, changing the way the index was parsed in _buildSpan fixed it.

Since the index we are interested in is surrounded by <highlight>, we can be sure that it won't contain any leading or trailing whitespace. So, I added a check before calling tryParse to get the index.

int? index;

// Only parse index if nextToDisplay doesn't have any leading or trailing whitespace
if (nextToDisplay.length == nextToDisplay.trim().length) {
  index = int.tryParse(nextToDisplay);
}

I've not tested this thoroughly, so YMMV.

@crizant
Copy link
Collaborator

crizant commented Sep 22, 2022

Another error case related to this issue is when the matching number word is a substring of a longer number:
i.e. text: 607856, word: 78.

@crizant
Copy link
Collaborator

crizant commented Aug 15, 2023

This has been fixed by #48, I think we don't have to pin it anymore? @desconexo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants