Compare commits

...

2 Commits

Author SHA1 Message Date
dom
88f0ab1dea opt chat item
Closes #2292

Signed-off-by: dom <githubaccount56556@proton.me>
2026-06-05 10:45:32 +08:00
dom
038285cbe6 fix parse opus
Signed-off-by: dom <githubaccount56556@proton.me>
2026-06-05 10:44:32 +08:00
5 changed files with 109 additions and 94 deletions

View File

@@ -1,6 +1,8 @@
import 'package:PiliPlus/common/style.dart' as common_style;
import 'package:PiliPlus/models/dynamics/result.dart';
import 'package:PiliPlus/models/dynamics/vote_model.dart';
import 'package:PiliPlus/utils/color_utils.dart';
import 'package:PiliPlus/utils/parse_int.dart';
class ArticleContentModel {
int? align;
@@ -124,14 +126,14 @@ class Word {
Word.fromJson(Map<String, dynamic> json) {
words = json['words'];
fontSize = (json['font_size'] as num?)?.toDouble();
if (json['font_size'] case final num rawSize when rawSize != 0) {
fontSize = rawSize.toDouble();
}
style = json['style'] == null ? null : Style.fromJson(json['style']);
color = json['color'] == null
? null
: int.tryParse(
'FF${(json['color'] as String).substring(1)}',
radix: 16,
);
if (json['color'] case final String rawColor
when rawColor.startsWith('#')) {
color = ColourUtils.parse2Int(json['color']);
}
fontLevel = json['font_level'];
}
@@ -275,7 +277,7 @@ class Music {
Music.fromJson(Map<String, dynamic> json) {
cover = json['cover'];
id = json['id'];
id = safeToInt(json['id']);
jumpUrl = json['jump_url'];
label = json['label'];
title = json['title'];
@@ -291,12 +293,12 @@ class Opus {
int? statView;
Opus.fromJson(Map<String, dynamic> json) {
authorMid = json['author']?['mid'];
authorMid = safeToInt(json['author']?['mid']);
authorName = json['author']?['name'];
cover = json['cover'];
jumpUrl = json['jump_url'];
title = json['title'];
statView = json['stat']?['view'];
statView = safeToInt(json['stat']?['view']);
}
}
@@ -317,9 +319,9 @@ class Live {
descSecond = json['desc_second'];
title = json['title'];
jumpUrl = json['jump_url'];
id = json['id'];
liveState = json['live_state'];
reserveType = json['reserve_type'];
id = safeToInt(json['id']);
liveState = safeToInt(json['live_state']);
reserveType = safeToInt(json['reserve_type']);
badgeText = json['badge']?['text'];
}
}

View File

@@ -1,4 +1,5 @@
import 'package:PiliPlus/utils/extension/iterable_ext.dart';
import 'package:PiliPlus/utils/parse_int.dart';
class SimpleVoteInfo {
int? choiceCnt;
@@ -22,14 +23,14 @@ class SimpleVoteInfo {
});
SimpleVoteInfo.fromJson(Map<String, dynamic> json) {
choiceCnt = json['choice_cnt'];
defaultShare = json['default_share'];
choiceCnt = safeToInt(json['choice_cnt']);
defaultShare = safeToInt(json['default_share']);
desc = json['desc'];
endTime = json['end_time'];
status = json['status'];
uid = json['uid'];
voteId = json['vote_id'];
joinNum = json['join_num'] ?? 0;
endTime = safeToInt(json['end_time']);
status = safeToInt(json['status']);
uid = safeToInt(json['uid']);
voteId = safeToInt(json['vote_id']);
joinNum = safeToInt(json['join_num']) ?? 0;
}
}

View File

@@ -260,7 +260,7 @@ class OpusContent extends StatelessWidget {
.toList(),
);
}
case 3 when (element.line != null):
case 3 when (element.line?.pic != null):
final height = element.line!.pic!.height?.toDouble();
return CachedNetworkImage(
fit: .contain,
@@ -336,6 +336,8 @@ class OpusContent extends StatelessWidget {
Text(ugc.title!),
Text(
ugc.descSecond!,
maxLines: 2,
overflow: .ellipsis,
style: TextStyle(
fontSize: 13,
color: colorScheme.outline,
@@ -378,6 +380,8 @@ class OpusContent extends StatelessWidget {
if (common.desc2 != null)
Text(
common.desc2!,
maxLines: 2,
overflow: .ellipsis,
style: TextStyle(
fontSize: 13,
color: colorScheme.outline,
@@ -415,6 +419,8 @@ class OpusContent extends StatelessWidget {
if (live.descSecond != null)
Text(
live.descSecond!,
maxLines: 2,
overflow: .ellipsis,
style: TextStyle(
fontSize: 13,
color: colorScheme.outline,
@@ -507,6 +513,8 @@ class OpusContent extends StatelessWidget {
if (music.label != null)
Text(
music.label!,
maxLines: 2,
overflow: .ellipsis,
style: TextStyle(
fontSize: 13,
color: colorScheme.outline,
@@ -693,9 +701,9 @@ class OpusContent extends StatelessWidget {
),
);
}
} catch (e) {
} catch (e, s) {
return SelectableText(
'错误的类型 $e',
'错误的类型 $e${kDebugMode ? '\n$s' : ''}',
style: const TextStyle(
fontWeight: .bold,
color: Colors.red,

View File

@@ -200,10 +200,8 @@ class ChatItem extends StatelessWidget {
Widget msgTypeCommonShareCard_14(dynamic content, Color textColor) {
if (content['source'] == '直播') {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
return GestureDetector(
behavior: .opaque,
onTap: () {
dynamic roomId = content['sourceID'];
if (roomId is String) {
@@ -211,12 +209,14 @@ class ChatItem extends StatelessWidget {
}
PageUtils.toLiveRoom(roomId);
},
child: NetworkImgLayer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
NetworkImgLayer(
width: 220,
height: 123.75,
src: content['cover'],
),
),
const SizedBox(height: 6),
Text(
content['title'] ?? "",
@@ -238,6 +238,7 @@ class ChatItem extends StatelessWidget {
),
),
],
),
);
} else {
return def(textColor);
@@ -246,6 +247,7 @@ class ChatItem extends StatelessWidget {
Widget msgTypeArticleCard_12(dynamic content, Color textColor) {
return GestureDetector(
behavior: .opaque,
onTap: () => Get.toNamed(
'/articlePage',
parameters: {
@@ -267,7 +269,7 @@ class ChatItem extends StatelessWidget {
],
),
const SizedBox(height: 6),
SelectableText(
Text(
content['title'] ?? "",
style: TextStyle(
letterSpacing: 0.6,
@@ -278,8 +280,7 @@ class ChatItem extends StatelessWidget {
),
if (content['summary'] != null && content['summary'] != '') ...[
const SizedBox(height: 1),
SelectableText(
scrollPhysics: const NeverScrollableScrollPhysics(),
Text(
content['summary'],
style: TextStyle(
letterSpacing: 0.6,
@@ -570,17 +571,17 @@ class ChatItem extends StatelessWidget {
'unsupported source type: ${content['source']}',
);
}
return Column(
return GestureDetector(
onTap: onTap,
behavior: .opaque,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
onTap: onTap,
child: NetworkImgLayer(
NetworkImgLayer(
width: 220,
height: 123.75,
src: content['thumb'],
),
),
const SizedBox(height: 6),
Text(
content['title'] ?? "",
@@ -617,6 +618,7 @@ class ChatItem extends StatelessWidget {
),
],
],
),
);
}
@@ -749,7 +751,7 @@ class ChatItem extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SelectableText(
Text(
content['title'],
style: theme.textTheme.titleMedium!.copyWith(
fontWeight: FontWeight.bold,

View File

@@ -1,8 +1,10 @@
import 'package:flutter/rendering.dart' show Color;
abstract final class ColourUtils {
static Color parseColor(String color) =>
Color(0xFF000000 | int.parse(color.substring(1), radix: 16));
static int parse2Int(String color) =>
0xFF000000 | int.parse(color.substring(1), radix: 16);
static Color parseColor(String color) => Color(parse2Int(color));
static Color parseMedalColor(String color) {
final rgba = int.parse(color.substring(1), radix: 16);