feat: replace linkify text
This commit is contained in:
parent
98299e28c4
commit
e64a0fc4fd
|
@ -132,7 +132,7 @@ class LinkifyText extends StatelessWidget {
|
||||||
|
|
||||||
final Map<LinkType, TextStyle>? customLinkStyles;
|
final Map<LinkType, TextStyle>? customLinkStyles;
|
||||||
|
|
||||||
final void Function(List<Link>)? linkifyListCallBack;
|
final Map<String,String>? linkifyListCallBack;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -143,7 +143,7 @@ class LinkifyText extends StatelessWidget {
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
linkTypes: linkTypes,
|
linkTypes: linkTypes,
|
||||||
customLinkStyles: customLinkStyles,
|
customLinkStyles: customLinkStyles,
|
||||||
linkifyListCallBack: linkifyListCallBack),
|
mapReplace: linkifyListCallBack),
|
||||||
key: key,
|
key: key,
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
strutStyle: strutStyle,
|
strutStyle: strutStyle,
|
||||||
|
@ -378,7 +378,7 @@ TextSpan _linkify({
|
||||||
List<LinkType>? linkTypes,
|
List<LinkType>? linkTypes,
|
||||||
Map<LinkType, TextStyle>? customLinkStyles,
|
Map<LinkType, TextStyle>? customLinkStyles,
|
||||||
Function(Link)? onTap,
|
Function(Link)? onTap,
|
||||||
Function(List<Link>)? linkifyListCallBack,
|
Map<String,String>? mapReplace,
|
||||||
}) {
|
}) {
|
||||||
final _regExp = constructRegExpFromLinkType(linkTypes ?? [LinkType.url]);
|
final _regExp = constructRegExpFromLinkType(linkTypes ?? [LinkType.url]);
|
||||||
|
|
||||||
|
@ -388,7 +388,6 @@ TextSpan _linkify({
|
||||||
final texts = text.split(_regExp);
|
final texts = text.split(_regExp);
|
||||||
final List<InlineSpan> spans = [];
|
final List<InlineSpan> spans = [];
|
||||||
final links = _regExp.allMatches(text).toList();
|
final links = _regExp.allMatches(text).toList();
|
||||||
final List<Link> linkifyList = [];
|
|
||||||
|
|
||||||
for (final text in texts) {
|
for (final text in texts) {
|
||||||
spans.add(TextSpan(
|
spans.add(TextSpan(
|
||||||
|
@ -400,7 +399,7 @@ TextSpan _linkify({
|
||||||
// add the link
|
// add the link
|
||||||
spans.add(
|
spans.add(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: link.value,
|
text:( mapReplace?[link.value??'']?.isNotEmpty??false) ? (mapReplace?[link.value??''] ??'' ): link.value,
|
||||||
style: customLinkStyles?[link.type] ?? linkStyle,
|
style: customLinkStyles?[link.type] ?? linkStyle,
|
||||||
recognizer: TapGestureRecognizer()
|
recognizer: TapGestureRecognizer()
|
||||||
..onTap = () {
|
..onTap = () {
|
||||||
|
@ -409,11 +408,9 @@ TextSpan _linkify({
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
linkifyList.add(link);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
linkifyListCallBack?.call(linkifyList);
|
|
||||||
|
|
||||||
return TextSpan(children: spans);
|
return TextSpan(children: spans);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue