From 80b39daaff4fbaa122b71f387ab0c1cfaadca0d9 Mon Sep 17 00:00:00 2001 From: guozhigq Date: Sun, 4 Feb 2024 22:06:45 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20jumpUrl=E5=A2=9E=E5=8A=A0icon=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=20issues=20#471?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/reply/widgets/reply_item.dart | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/lib/pages/video/detail/reply/widgets/reply_item.dart b/lib/pages/video/detail/reply/widgets/reply_item.dart index 5e5a5828..7991a366 100644 --- a/lib/pages/video/detail/reply/widgets/reply_item.dart +++ b/lib/pages/video/detail/reply/widgets/reply_item.dart @@ -571,7 +571,8 @@ InlineSpan buildContent( }); } // content.message = content.message.replaceAll(RegExp(r"\{vote:.*?\}"), ' '); - content.message = content.message.replaceAll('&', '&') + content.message = content.message + .replaceAll('&', '&') .replaceAll('<', '<') .replaceAll('>', '>') .replaceAll('"', '"') @@ -586,21 +587,21 @@ InlineSpan buildContent( e.replaceAll('?', '\\?').replaceAll('+', '\\+').replaceAll('*', '\\*')), ]; - String patternStr = - specialTokens.map(RegExp.escape).join('|'); + String patternStr = specialTokens.map(RegExp.escape).join('|'); if (patternStr.isNotEmpty) { patternStr += "|"; } patternStr += r'(\b\d{1,2}[::]\d{2}\b)'; final RegExp pattern = RegExp(patternStr); List matchedStrs = []; - void addPlainTextSpan(str){ + void addPlainTextSpan(str) { spanChilds.add(TextSpan( text: str, recognizer: TapGestureRecognizer() - ..onTap = () => - replyReply(replyItem.root == 0 ? replyItem : fReplyItem))); + ..onTap = + () => replyReply(replyItem.root == 0 ? replyItem : fReplyItem))); } + // 分割文本并处理每个部分 content.message.splitMapJoin( pattern, @@ -674,57 +675,56 @@ InlineSpan buildContent( addPlainTextSpan(matchStr); return ""; } - spanChilds.add( - TextSpan( - text: content.jumpUrl[matchStr]['title'], - style: TextStyle( - color: Theme.of(context).colorScheme.primary, - ), - recognizer: TapGestureRecognizer() - ..onTap = () { - if (appUrlSchema == '') { - final String str = Uri.parse(matchStr).pathSegments[0]; - final Map matchRes = IdUtils.matchAvorBv(input: str); - final List matchKeys = matchRes.keys.toList(); - if (matchKeys.isNotEmpty) { - if (matchKeys.first == 'BV') { + spanChilds.addAll( + [ + if (content.jumpUrl[matchStr]?['prefix_icon'] != null) ...[ + WidgetSpan( + child: Image.network( + content.jumpUrl[matchStr]['prefix_icon'], + height: 19, + color: Theme.of(context).colorScheme.primary, + ), + ) + ], + TextSpan( + text: content.jumpUrl[matchStr]['title'], + style: TextStyle( + color: Theme.of(context).colorScheme.primary, + ), + recognizer: TapGestureRecognizer() + ..onTap = () { + if (appUrlSchema == '') { + final String str = Uri.parse(matchStr).pathSegments[0]; + final Map matchRes = IdUtils.matchAvorBv(input: str); + final List matchKeys = matchRes.keys.toList(); + if (matchKeys.isNotEmpty) { + if (matchKeys.first == 'BV') { + Get.toNamed( + '/searchResult', + parameters: {'keyword': matchRes['BV']}, + ); + } + } else { Get.toNamed( - '/searchResult', - parameters: {'keyword': matchRes['BV']}, + '/webview', + parameters: { + 'url': matchStr, + 'type': 'url', + 'pageTitle': '' + }, ); } } else { - Get.toNamed( - '/webview', - parameters: { - 'url': matchStr, - 'type': 'url', - 'pageTitle': '' - }, - ); + if (appUrlSchema.startsWith('bilibili://search')) { + Get.toNamed('/searchResult', parameters: { + 'keyword': content.jumpUrl[matchStr]['title'] + }); + } } - } else { - if (appUrlSchema.startsWith('bilibili://search')) { - Get.toNamed('/searchResult', parameters: { - 'keyword': content.jumpUrl[matchStr]['title'] - }); - } - } - }, - ), + }, + ) + ], ); - if (appUrlSchema.startsWith('bilibili://search')) { - spanChilds.add( - WidgetSpan( - child: Icon( - FontAwesomeIcons.magnifyingGlass, - size: 9, - color: Theme.of(context).colorScheme.primary, - ), - alignment: PlaceholderAlignment.top, - ), - ); - } // 只显示一次 matchedStrs.add(matchStr); } else {