Flutter 实现富文本

278 阅读1分钟

富文本是很多App都需要的,而且Flutter也提供了富文本功能,但是对于做多语言的APP来说,RichText并不好用,或者说不能用, 今天就给大家推荐一个第三方库 rich_text_widget

使用起来简单又方便,不用分割字符串 具体使用方法参考如下

RichTextWidget(
      // default Text
      Text(
        'You have pushed the button this many times:',
        style: TextStyle(color: Colors.black),
      ),
      // rich text list
      richTexts: [
        BaseRichText(
          "pushed",
          style: TextStyle(color: Colors.yellow),
          onTap: () => {print("touch pushed")},
        ),
        BaseRichText(
          "button",
          style: TextStyle(color: Colors.red),
          onTap: () => {print("touch button")},
        ),
      ],
    )

展示效果如下 !

参数说明

RichTextWidget:

Nametype
defaultTextText
richTextsList <BaseRichText>
caseSensitivebool (defalut = true)

BaseRichText:

Nametype
dataString
styleTextStyle
onTapFunction