From 2d13367f69eb2441a3a85f72ec1610b293989c6b Mon Sep 17 00:00:00 2001 From: guozhigq Date: Mon, 17 Jul 2023 12:30:10 +0800 Subject: [PATCH] =?UTF-8?q?mod:=20=E8=A7=86=E9=A2=91=E7=AE=80=E4=BB=8B?= =?UTF-8?q?=E5=AF=8C=E6=96=87=E6=9C=AC=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/video/reply/content.dart | 5 +- lib/pages/video/detail/introduction/view.dart | 46 ++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/lib/models/video/reply/content.dart b/lib/models/video/reply/content.dart index 44b90eac..7fcea857 100644 --- a/lib/models/video/reply/content.dart +++ b/lib/models/video/reply/content.dart @@ -19,7 +19,10 @@ class ReplyContent { Map? richText; ReplyContent.fromJson(Map json) { - message = json['message'].replaceAll('>', '>').replaceAll('"', '"'); + message = json['message'] + .replaceAll('>', '>') + .replaceAll('"', '"') + .replaceAll(''', "'"); atNameToMid = json['at_name_to_mid'] ?? {}; memebers = json['memebers'] ?? []; emote = json['emote'] ?? {}; diff --git a/lib/pages/video/detail/introduction/view.dart b/lib/pages/video/detail/introduction/view.dart index 3af63792..8d372942 100644 --- a/lib/pages/video/detail/introduction/view.dart +++ b/lib/pages/video/detail/introduction/view.dart @@ -1,4 +1,5 @@ import 'package:flutter/cupertino.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; @@ -340,7 +341,14 @@ class _VideoInfoState extends State with TickerProviderStateMixin { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(widget.videoDetail!.bvid!), - Text(widget.videoDetail!.desc!), + Text.rich( + TextSpan( + children: [ + buildContent( + context, widget.videoDetail!), + ], + ), + ), ], ), ), @@ -536,6 +544,42 @@ class _VideoInfoState extends State with TickerProviderStateMixin { ); }); } + + InlineSpan buildContent(BuildContext context, content) { + String desc = content.desc; + List descV2 = content.descV2; + // type + // 1 普通文本 + // 2 @用户 + List spanChilds = []; + if (descV2.isNotEmpty) { + for (var i = 0; i < descV2.length; i++) { + if (descV2[i].type == 1) { + spanChilds.add(TextSpan(text: descV2[i].rawText)); + } else if (descV2[i].type == 2) { + spanChilds.add( + TextSpan( + text: '@${descV2[i].rawText}', + style: TextStyle( + color: Theme.of(context).colorScheme.primary, + ), + recognizer: TapGestureRecognizer() + ..onTap = () { + String heroTag = Utils.makeHeroTag(descV2[i].bizId); + Get.toNamed( + '/member?mid=${descV2[i].bizId}', + arguments: {'face': '', 'heroTag': heroTag}, + ); + }, + ), + ); + } + } + } else { + spanChilds.add(TextSpan(text: desc)); + } + return TextSpan(children: spanChilds); + } } class ActionItem extends StatelessWidget {