easy_rich_text_ontap 0.1.1 copy "easy_rich_text_ontap: ^0.1.1" to clipboard
easy_rich_text_ontap: ^0.1.1 copied to clipboard

这个包由easy_rich_text包修改而来,将原包中的EasyRichTextPattern新增了onTap事件,接收其自身的targetString为参数。

easy_rich_text_ontap #

这个包由easy_rich_text包修改而来,将原包中的EasyRichTextPattern新增了onTap事件,接收其自身的targetString为参数

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.1.1'

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),
      onTap: (String str){
          print(str);   // 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 blue superscript font here. I want no blue font here";

EasyRichText(
  str3,
  patternList: [
    EasyRichTextPattern(
        targetString: 'blue',
        stringBeforeTarget: 'want',
        style: TextStyle(color: Colors.blue),
        superScript: true),
  ],
  textAlign: TextAlign.justify,
),

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,
),

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),
    ),
  ],
),
not all characters support superscript and subscript

Characters do not support superscript: q z C F Q S X Y Z.

Only these characters support subscript: e h i j k l m n o p r s t u v x.

0
likes
30
pub points
0%
popularity

Publisher

unverified uploader

这个包由easy_rich_text包修改而来,将原包中的EasyRichTextPattern新增了onTap事件,接收其自身的targetString为参数。

Homepage

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on easy_rich_text_ontap