fix and fix dynamics render

This commit is contained in:
guozhigq
2023-09-08 17:21:11 +08:00
parent 81dace96d7
commit 72ff3fdab0
3 changed files with 107 additions and 96 deletions

View File

@ -162,6 +162,9 @@ class DynamicsController extends GetxController {
/// 纯文字动态查看 /// 纯文字动态查看
case 'DYNAMIC_TYPE_WORD': case 'DYNAMIC_TYPE_WORD':
print('纯文本'); print('纯文本');
if (item.modules.moduleDynamic.major.draw == null) {
return;
}
Get.toNamed('/dynamicDetail', Get.toNamed('/dynamicDetail',
arguments: {'item': item, 'floor': floor}); arguments: {'item': item, 'floor': floor});
break; break;

View File

@ -137,7 +137,12 @@ Widget forWard(item, context, ctr, source, {floor = 1}) {
], ],
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Text(item.modules.moduleDynamic.desc.text) Text.rich(
richNode(item, context),
// 被转发状态(floor=2) 隐藏
maxLines: source == 'detail' && floor != 2 ? 999 : 4,
overflow: TextOverflow.ellipsis,
),
], ],
) )
: item.modules.moduleDynamic.additional != null : item.modules.moduleDynamic.additional != null

View File

@ -26,7 +26,7 @@ InlineSpan richNode(item, context) {
} else { } else {
for (var i in richTextNodes) { for (var i in richTextNodes) {
/// fix 渲染专栏时内容会重复 /// fix 渲染专栏时内容会重复
if (item.modules.moduleDynamic.major.opus.title == null && if (item.modules.moduleDynamic.major?.opus?.title == null &&
i.type == 'RICH_TEXT_NODE_TYPE_TEXT') { i.type == 'RICH_TEXT_NODE_TYPE_TEXT') {
spanChilds.add( spanChilds.add(
TextSpan(text: i.origText, style: const TextStyle(height: 1.65))); TextSpan(text: i.origText, style: const TextStyle(height: 1.65)));
@ -192,113 +192,116 @@ InlineSpan richNode(item, context) {
); );
} }
} }
if (contentType == 'major' && try {
item.modules.moduleDynamic.major.opus.pics.isNotEmpty) { if (contentType == 'major' &&
// 图片可能跟其他widget重复渲染 item.modules.moduleDynamic.major.opus.pics.isNotEmpty) {
print('有图片'); // 图片可能跟其他widget重复渲染
List<OpusPicsModel> pics = item.modules.moduleDynamic.major.opus.pics; List<OpusPicsModel> pics = item.modules.moduleDynamic.major.opus.pics;
int len = pics.length; int len = pics.length;
List picList = []; List picList = [];
if (len == 1) { if (len == 1) {
OpusPicsModel pictureItem = pics.first; OpusPicsModel pictureItem = pics.first;
picList.add(pictureItem.url); picList.add(pictureItem.url);
spanChilds.add(const TextSpan(text: '\n')); spanChilds.add(const TextSpan(text: '\n'));
spanChilds.add( spanChilds.add(
WidgetSpan( WidgetSpan(
child: LayoutBuilder( child: LayoutBuilder(
builder: (context, BoxConstraints box) { builder: (context, BoxConstraints box) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Get.toNamed('/preview', Get.toNamed('/preview',
arguments: {'initialPage': 0, 'imgList': picList}); arguments: {'initialPage': 0, 'imgList': picList});
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.only(top: 4), padding: const EdgeInsets.only(top: 4),
child: NetworkImgLayer( child: NetworkImgLayer(
src: pictureItem.url, src: pictureItem.url,
width: box.maxWidth / 2, width: box.maxWidth / 2,
height: box.maxWidth * height: box.maxWidth *
0.5 * 0.5 *
pictureItem.height! / pictureItem.height! /
pictureItem.width!, pictureItem.width!,
),
), ),
), );
); },
}, ),
),
),
);
}
if (len > 1) {
List<Widget> list = [];
for (var i = 0; i < len; i++) {
picList.add(pics[i].url);
list.add(
LayoutBuilder(
builder: (context, BoxConstraints box) {
return GestureDetector(
onTap: () {
Get.toNamed('/preview',
arguments: {'initialPage': i, 'imgList': picList});
},
child: NetworkImgLayer(
src: pics[i].url,
width: box.maxWidth,
height: box.maxWidth,
),
);
},
), ),
); );
} }
spanChilds.add( if (len > 1) {
WidgetSpan( List<Widget> list = [];
child: LayoutBuilder( for (var i = 0; i < len; i++) {
builder: (context, BoxConstraints box) { picList.add(pics[i].url);
double maxWidth = box.maxWidth; list.add(
double crossCount = len < 3 ? 2 : 3; LayoutBuilder(
double height = maxWidth / builder: (context, BoxConstraints box) {
crossCount * return GestureDetector(
(len % crossCount == 0 onTap: () {
? len ~/ crossCount Get.toNamed('/preview',
: len ~/ crossCount + 1) + arguments: {'initialPage': i, 'imgList': picList});
6; },
return Container( child: NetworkImgLayer(
padding: const EdgeInsets.only(top: 6), src: pics[i].url,
height: height, width: box.maxWidth,
child: GridView.count( height: box.maxWidth,
padding: EdgeInsets.zero, ),
physics: const NeverScrollableScrollPhysics(), );
crossAxisCount: crossCount.toInt(), },
mainAxisSpacing: 4.0, ),
crossAxisSpacing: 4.0, );
childAspectRatio: 1, }
children: list, spanChilds.add(
), WidgetSpan(
); child: LayoutBuilder(
}, builder: (context, BoxConstraints box) {
double maxWidth = box.maxWidth;
double crossCount = len < 3 ? 2 : 3;
double height = maxWidth /
crossCount *
(len % crossCount == 0
? len ~/ crossCount
: len ~/ crossCount + 1) +
6;
return Container(
padding: const EdgeInsets.only(top: 6),
height: height,
child: GridView.count(
padding: EdgeInsets.zero,
physics: const NeverScrollableScrollPhysics(),
crossAxisCount: crossCount.toInt(),
mainAxisSpacing: 4.0,
crossAxisSpacing: 4.0,
childAspectRatio: 1,
children: list,
),
);
},
),
), ),
), );
); }
// spanChilds.add(
// WidgetSpan(
// child: NetworkImgLayer(
// src: pics.first.url,
// type: 'emote',
// width: 100,
// height: 200,
// ),
// ),
// );
} }
// spanChilds.add( } catch (err) {
// WidgetSpan( print('❌rich_node_panel err: $err');
// child: NetworkImgLayer(
// src: pics.first.url,
// type: 'emote',
// width: 100,
// height: 200,
// ),
// ),
// );
} }
return TextSpan( return TextSpan(
children: spanChilds, children: spanChilds,
); );
} }
} catch (err) { } catch (err) {
print('❌rich_node_panel err: $err'); print('rich_node_panel err: $err');
return spacer; return spacer;
} }
} }