easy_rich_text 0.2.4 copy "easy_rich_text: ^0.2.4" to clipboard
easy_rich_text: ^0.2.4 copied to clipboard

outdated

The EasyRichText widget provides a easy way to use RichText when you want to use specific style for specific word.

easy_rich_text #

The EasyRichText widget provides a easy way to use RichText when you want to use specific style for specific word pattern. This widget would be useful when you want to apply RichText to text get from a query. For example, highlight a company name or a product trademark.

This widget split string into multiple TextSpan by defining a List of EasyRichTextPattern();

The EasyRichTextPattern is a class defines the text pattern you want to format.

Getting Started #

Installing: #

dependencies:
  easy_rich_text: '^0.2.4'

Simple example:

alt text

String str1 = "This is a EasyRichText example. I want blue font. I want bold font. I want italic font. ";

EasyRichText(
  str1,
  patternList: [
    EasyRichTextPattern(
      targetString: 'blue',
      style: TextStyle(color: Colors.blue),
    ),
    EasyRichTextPattern(
      targetString: 'bold',
      style: TextStyle(fontWeight: FontWeight.bold),
    ),
    EasyRichTextPattern(
      targetString: 'italic',
      style: TextStyle(fontStyle: FontStyle.italic),
    ),
  ],
),

Default Style:

alt text

String str2 = "This is a EasyRichText example with default grey font. I want blue font here.";

EasyRichText(
  str2,
  defaultStyle: TextStyle(color: Colors.grey),
  patternList: [
    EasyRichTextPattern(
      targetString: 'blue',
      style: TextStyle(color: Colors.blue),
    ),
    EasyRichTextPattern(
      targetString: 'bold',
      style: TextStyle(fontWeight: FontWeight.bold),
    ),
  ],
),

superscript and subscript.

alt text

String str3 = "This is a EasyRichText example. I want superscript font here. I want subscript here";

EasyRichText(
  str4,
  patternList: [
    EasyRichTextPattern(
        targetString: 'superscript', superScript: true),
    EasyRichTextPattern(
        targetString: 'subscript', subScript: true),
  ],
),

All RichText properties accessible: textAlign, maxLines, overflow, etc.

alt text

String str4 = "This is a EasyRichText example. I want blue font here. TextOverflow.ellipsis, TextAlign.justify, maxLines: 1";

EasyRichText(
  str4,
  patternList: [
    EasyRichTextPattern(
      targetString: 'blue',
      stringBeforeTarget: 'want',
      style: TextStyle(color: Colors.blue),
    ),
  ],
  textAlign: TextAlign.justify,
  maxLines: 1,
  overflow: TextOverflow.ellipsis,
),

Case Sensitivity (default true) #

alt text

String str7 = "Case-Insensitive String Matching. I want both Blue and blue.";

EasyRichText(
  str7,
  caseSensitive: false,
  patternList: [
    EasyRichTextPattern(
      targetString: 'blue',
      style: TextStyle(color: Colors.blue),
    ),
  ],
),

Trademark #

alt text

String str = "ProductTM is a superscript trademark symbol. This TM is not a trademark.";

EasyRichText(
  str,
  patternList: [
    EasyRichTextPattern(
      targetString: 'TM',
      superScript: true,
      stringBeforeTarget: 'Product',
      matchWordBoundaries: false,
      style: TextStyle(color: Colors.blue),
    ),
  ],
),

Known issues

Conflict when one target string is included in another target string

alt text

String str6 = "This is a EasyRichText example. I want whole sentence blue. I want whole sentence bold.";

EasyRichText(
  str6,
  patternList: [
    EasyRichTextPattern(
      targetString: 'blue',
      style: TextStyle(color: Colors.blue),
    ),
    EasyRichTextPattern(
      targetString: 'I want whole sentence blue',
      style: TextStyle(fontWeight: FontWeight.bold),
    ),
    EasyRichTextPattern(
      targetString: 'I want whole sentence bold',
      style: TextStyle(fontWeight: FontWeight.bold),
    ),
  ],
),
206
likes
0
pub points
96%
popularity

Publisher

verified publisherhyclovechj.com

The EasyRichText widget provides a easy way to use RichText when you want to use specific style for specific word.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on easy_rich_text