link_rich_text

Last updated:

0 purchases

link_rich_text Image
link_rich_text Images
Add to Cart

Description:

link rich text

link_rich_text #


Flutter plugin for hyperlinks and custom special characters rich text display.
Demo #

Installation #
In your pubspec.yaml file within your Flutter Project:
dependencies:
link_rich_text: 3.0.2
copied to clipboard
Use it #
import 'package:link_rich_text/link_rich_text.dart';
copied to clipboard
Through LinkRichModel #
Create model
_setLinkRichModel() async {
// 对于性能要求高的场景,比如列表中,
// 可在加载好数据的同时就设置好富文本模型(LinkRichModel)
// 并将模型传入LinkRichText中,或将模型的textSpan属性传入RichText中显示

// 添加特殊字符串
List<SpecialStr> specialStrs = <SpecialStr>[];
specialStrs.add(SpecialStr(
text: '@我啊',
type: 'user',
style: const TextStyle(fontSize: 15, color: Colors.blue)));
specialStrs.add(SpecialStr(
text: '@我啊啊',
type: 'user',
style: const TextStyle(fontSize: 18, color: Colors.purple)));
specialStrs.add(SpecialStr(
text: '@一只鱼',
type: 'user',
style: const TextStyle(fontSize: 15, color: Colors.orange)));
specialStrs.add(SpecialStr(
text: '@不老实的鸟',
type: 'user',
style: const TextStyle(fontSize: 15, color: Colors.brown)));

// 添加正则特殊字符串
List<RegExpStr> regExpStrs = <RegExpStr>[];
regExpStrs.add(RegExpStr(
text: '#\\S*? ',
type: '#',
style: const TextStyle(fontSize: 18, color: Colors.lightBlueAccent)));

String text = '@一只鱼 控件打底可反#馈的 了老@我啊都放到裤积分 '
'快进快手动,肯德的框架反馈的减@我啊啊肥看的积分基疯狂的发,'
'发拉拉速度快积分@哈哈卢萨卡的积分禄口街道和你是谁 @不老实的鸟 ?是吗';

// 创建并缓存富文本模型
_linkRichModel = LinkRichModel(
text,
style: const TextStyle(fontSize: 15, color: Colors.black),
linkStyle: const TextStyle(fontSize: 18, color: Colors.red),
specialStrs: specialStrs,
regExpStrs: regExpStrs,
onTapSpecialStr: (String text, String type) {
if (kDebugMode) {
print('type = $type, text = $text');
}
},
);

setState(() {});
}
copied to clipboard
Display rich text through the model
LinkRichText.fromModel(_linkRichModel!),
copied to clipboard
or
RichText(text: _linkRichModel!.textSpan),
copied to clipboard
Through LinkRichText directly #
LinkRichText(
text,
style: const TextStyle(fontSize: 15, color: Colors.black),
linkStyle: const TextStyle(fontSize: 15, color: Colors.blue),
specialStrs: specialStrs,
regExpStrs: regExpStrs,
onTapSpecialStr: (String text, String type) {
if (kDebugMode) {
print('type = $type, text = $text');
}
if (type == 'link') {
launchUrlString(text);
}
},
)
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.