opt: dynamic panel

This commit is contained in:
bggRGjQaUbCoE
2024-12-30 11:56:03 +08:00
parent ef8d57ddfd
commit 753fdeea03
7 changed files with 71 additions and 58 deletions

View File

@@ -36,6 +36,7 @@ class Content extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
TextStyle authorStyle = TextStyle authorStyle =
TextStyle(color: Theme.of(context).colorScheme.primary); TextStyle(color: Theme.of(context).colorScheme.primary);
InlineSpan? richNodes = richNode(item, context);
return Container( return Container(
width: double.infinity, width: double.infinity,
@@ -51,6 +52,7 @@ class Content extends StatelessWidget {
), ),
), ),
], ],
if (richNodes != null)
IgnorePointer( IgnorePointer(
// 禁用SelectableRegion的触摸交互功能 // 禁用SelectableRegion的触摸交互功能
ignoring: source == 'detail' ? false : true, ignoring: source == 'detail' ? false : true,
@@ -64,7 +66,7 @@ class Content extends StatelessWidget {
height: 0, height: 0,
fontSize: source == 'detail' ? 16 : 15, fontSize: source == 'detail' ? 16 : 15,
), ),
richNode(item, context), richNodes,
maxLines: source == 'detail' ? 999 : 6, maxLines: source == 'detail' ? 999 : 6,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),

View File

@@ -38,7 +38,7 @@ class ContentGrpc extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
TextStyle authorStyle = TextStyle authorStyle =
TextStyle(color: Theme.of(context).colorScheme.primary); TextStyle(color: Theme.of(context).colorScheme.primary);
InlineSpan? richNodes = richNode(item, context);
return Container( return Container(
width: double.infinity, width: double.infinity,
padding: const EdgeInsets.fromLTRB(12, 0, 12, 6), padding: const EdgeInsets.fromLTRB(12, 0, 12, 6),
@@ -53,6 +53,7 @@ class ContentGrpc extends StatelessWidget {
), ),
), ),
], ],
if (richNodes != null)
IgnorePointer( IgnorePointer(
// 禁用SelectableRegion的触摸交互功能 // 禁用SelectableRegion的触摸交互功能
ignoring: source == 'detail' ? false : true, ignoring: source == 'detail' ? false : true,
@@ -63,7 +64,7 @@ class ContentGrpc extends StatelessWidget {
child: Text.rich( child: Text.rich(
/// fix 默认20px高度 /// fix 默认20px高度
style: const TextStyle(height: 0), style: const TextStyle(height: 0),
richNode(item, context), richNodes,
maxLines: source == 'detail' ? 999 : 6, maxLines: source == 'detail' ? 999 : 6,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),

View File

@@ -45,6 +45,7 @@ Widget forWard(item, context, ctr, source, {floor = 1}) {
if (hasPics) { if (hasPics) {
pics = item.modules.moduleDynamic.major.opus.pics; pics = item.modules.moduleDynamic.major.opus.pics;
} }
InlineSpan? richNodes = richNode(item, context);
switch (item.type) { switch (item.type) {
// 图文 // 图文
case 'DYNAMIC_TYPE_DRAW': case 'DYNAMIC_TYPE_DRAW':
@@ -89,8 +90,9 @@ Widget forWard(item, context, ctr, source, {floor = 1}) {
// ), // ),
// ), // ),
// ], // ],
if (richNodes != null)
Text.rich( Text.rich(
richNode(item, context), richNodes,
// 被转发状态(floor=2) 隐藏 // 被转发状态(floor=2) 隐藏
maxLines: source == 'detail' && floor != 2 ? 999 : 4, maxLines: source == 'detail' && floor != 2 ? 999 : 4,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
@@ -180,8 +182,9 @@ Widget forWard(item, context, ctr, source, {floor = 1}) {
], ],
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
if (richNodes != null)
Text.rich( Text.rich(
richNode(item, context), richNodes,
// 被转发状态(floor=2) 隐藏 // 被转发状态(floor=2) 隐藏
maxLines: source == 'detail' && floor != 2 ? 999 : 4, maxLines: source == 'detail' && floor != 2 ? 999 : 4,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,

View File

@@ -9,6 +9,7 @@ Widget livePanel(item, context, {floor = 1}) {
dynamic content = item.modules.moduleDynamic.major; dynamic content = item.modules.moduleDynamic.major;
TextStyle authorStyle = TextStyle authorStyle =
TextStyle(color: Theme.of(context).colorScheme.primary); TextStyle(color: Theme.of(context).colorScheme.primary);
InlineSpan? richNodes = richNode(item, context);
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@@ -50,7 +51,7 @@ Widget livePanel(item, context, {floor = 1}) {
const SizedBox(height: 6), const SizedBox(height: 6),
], ],
if (floor == 2 && item.modules.moduleDynamic.desc != null) ...[ if (floor == 2 && item.modules.moduleDynamic.desc != null) ...[
Text.rich(richNode(item, context)), if (richNodes != null) Text.rich(richNodes),
const SizedBox(height: 6), const SizedBox(height: 6),
], ],
GestureDetector( GestureDetector(

View File

@@ -16,6 +16,7 @@ Widget liveRcmdPanel(item, context, {floor = 1}) {
DynamicLiveModel liveRcmd = item.modules.moduleDynamic.major.liveRcmd; DynamicLiveModel liveRcmd = item.modules.moduleDynamic.major.liveRcmd;
int liveStatus = liveRcmd.liveStatus!; int liveStatus = liveRcmd.liveStatus!;
Map watchedShow = liveRcmd.watchedShow!; Map watchedShow = liveRcmd.watchedShow!;
InlineSpan? richNodes = richNode(item, context);
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@@ -56,7 +57,7 @@ Widget liveRcmdPanel(item, context, {floor = 1}) {
const SizedBox(height: 6), const SizedBox(height: 6),
], ],
if (floor == 2 && item.modules.moduleDynamic.desc != null) ...[ if (floor == 2 && item.modules.moduleDynamic.desc != null) ...[
Text.rich(richNode(item, context)), if (richNodes != null) Text.rich(richNodes),
const SizedBox(height: 6), const SizedBox(height: 6),
], ],
Padding( Padding(

View File

@@ -1,3 +1,4 @@
import 'package:PiliPalaX/models/dynamics/result.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@@ -6,21 +7,21 @@ import 'package:PiliPalaX/http/search.dart';
import 'package:PiliPalaX/utils/app_scheme.dart'; import 'package:PiliPalaX/utils/app_scheme.dart';
// 富文本 // 富文本
InlineSpan richNode(item, context) { InlineSpan? richNode(item, context) {
final spacer = _VerticalSpaceSpan(0.0); final spacer = _VerticalSpaceSpan(0.0);
try { try {
TextStyle authorStyle = TextStyle authorStyle =
TextStyle(color: Theme.of(context).colorScheme.primary); TextStyle(color: Theme.of(context).colorScheme.primary);
List<InlineSpan> spanChildren = []; List<InlineSpan> spanChildren = [];
dynamic richTextNodes; List<RichTextNodeItem>? richTextNodes;
if (item.modules.moduleDynamic.desc != null) { if (item.modules.moduleDynamic.desc != null) {
richTextNodes = item.modules.moduleDynamic.desc.richTextNodes; richTextNodes = item.modules.moduleDynamic.desc.richTextNodes;
} else if (item.modules.moduleDynamic.major != null) { } else if (item.modules.moduleDynamic.major != null) {
// 动态页面 richTextNodes 层级可能与主页动态层级不同 // 动态页面 richTextNodes 层级可能与主页动态层级不同
richTextNodes = richTextNodes =
item.modules.moduleDynamic.major.opus.summary.richTextNodes; item.modules.moduleDynamic.major.opus?.summary?.richTextNodes;
if (item.modules.moduleDynamic.major.opus.title != null) { if (item.modules.moduleDynamic.major.opus?.title != null) {
spanChildren.add( spanChildren.add(
TextSpan( TextSpan(
text: item.modules.moduleDynamic.major.opus.title + '\n', text: item.modules.moduleDynamic.major.opus.title + '\n',
@@ -33,7 +34,7 @@ InlineSpan richNode(item, context) {
} }
} }
if (richTextNodes == null || richTextNodes.isEmpty) { if (richTextNodes == null || richTextNodes.isEmpty) {
return spacer; return null;
} else { } else {
for (var i in richTextNodes) { for (var i in richTextNodes) {
/// fix 渲染专栏时内容会重复 /// fix 渲染专栏时内容会重复
@@ -96,7 +97,11 @@ InlineSpan richNode(item, context) {
alignment: PlaceholderAlignment.middle, alignment: PlaceholderAlignment.middle,
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () {
String url = i.origText; String? url = i.origText;
if (url == null) {
SmartDialog.showToast('未获取到链接');
return;
}
if (url.startsWith('//')) { if (url.startsWith('//')) {
url = url.replaceFirst('//', 'https://'); url = url.replaceFirst('//', 'https://');
PiliScheme.routePush(Uri.parse(url)); PiliScheme.routePush(Uri.parse(url));
@@ -114,7 +119,7 @@ InlineSpan richNode(item, context) {
); );
}, },
child: Text( child: Text(
i.text, i.text ?? '',
style: authorStyle, style: authorStyle,
), ),
), ),
@@ -150,14 +155,14 @@ InlineSpan richNode(item, context) {
); );
} }
// 表情 // 表情
if (i.type == 'RICH_TEXT_NODE_TYPE_EMOJI') { if (i.type == 'RICH_TEXT_NODE_TYPE_EMOJI' && i.emoji != null) {
spanChildren.add( spanChildren.add(
WidgetSpan( WidgetSpan(
child: NetworkImgLayer( child: NetworkImgLayer(
src: i.emoji.iconUrl, src: i.emoji!.iconUrl,
type: 'emote', type: 'emote',
width: i.emoji.size * 20, width: (i.emoji!.size ?? 1) * 20,
height: i.emoji.size * 20, height: (i.emoji!.size ?? 1) * 20,
), ),
), ),
); );

View File

@@ -24,7 +24,7 @@ Widget videoSeasonWidget(item, context, type, {floor = 1}) {
'pgc': item.modules.moduleDynamic.major.pgc 'pgc': item.modules.moduleDynamic.major.pgc
}; };
dynamic content = dynamicProperty[type]; dynamic content = dynamicProperty[type];
InlineSpan? richNodes = richNode(item, context);
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
@@ -73,7 +73,7 @@ Widget videoSeasonWidget(item, context, type, {floor = 1}) {
// const SizedBox(height: 6), // const SizedBox(height: 6),
// ], // ],
if (floor == 2 && item.modules.moduleDynamic.desc != null) ...[ if (floor == 2 && item.modules.moduleDynamic.desc != null) ...[
Text.rich(richNode(item, context)), if (richNodes != null) Text.rich(richNodes),
const SizedBox(height: 6), const SizedBox(height: 6),
], ],
Padding( Padding(