From f003e8bf35f4b30e9212c532d900807d9eb39771 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Sun, 30 Mar 2025 12:10:47 +0800 Subject: [PATCH] mod: member card: show prInfo Closes #571 Signed-off-by: bggRGjQaUbCoE --- lib/models/space/card.dart | 7 ++- lib/models/space/card.g.dart | 8 +-- lib/models/space/pr_info.dart | 42 +++++++++---- .../member/new/widget/user_info_card.dart | 60 +++++++++++++++++++ 4 files changed, 99 insertions(+), 18 deletions(-) diff --git a/lib/models/space/card.dart b/lib/models/space/card.dart index 2784fd62..78bceb44 100644 --- a/lib/models/space/card.dart +++ b/lib/models/space/card.dart @@ -1,3 +1,4 @@ +import 'package:PiliPlus/models/space/pr_info.dart'; import 'package:PiliPlus/models/space/space_tag_bottom.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -58,8 +59,8 @@ class Card { String? pendantUrl; @JsonKey(name: 'pendant_title') String? pendantTitle; - // @JsonKey(name: 'pr_info') - // PrInfo? prInfo; + @JsonKey(name: 'pr_info') + PrInfo? prInfo; Relation? relation; @JsonKey(name: 'is_deleted') int? isDeleted; @@ -120,7 +121,7 @@ class Card { this.achieve, this.pendantUrl, this.pendantTitle, - // this.prInfo, + this.prInfo, this.relation, this.isDeleted, this.honours, diff --git a/lib/models/space/card.g.dart b/lib/models/space/card.g.dart index a858fcd2..70f7af5e 100644 --- a/lib/models/space/card.g.dart +++ b/lib/models/space/card.g.dart @@ -58,9 +58,9 @@ Card _$CardFromJson(Map json) => Card( : Achieve.fromJson(json['achieve'] as Map), pendantUrl: json['pendant_url'] as String?, pendantTitle: json['pendant_title'] as String?, - // prInfo: json['pr_info'] == null - // ? null - // : PrInfo.fromJson(json['pr_info'] as Map), + prInfo: json['pr_info'] == null + ? null + : PrInfo.fromJson(json['pr_info'] as Map), relation: json['relation'] == null ? null : Relation.fromJson(json['relation'] as Map), @@ -131,7 +131,7 @@ Map _$CardToJson(Card instance) => { 'achieve': instance.achieve, 'pendant_url': instance.pendantUrl, 'pendant_title': instance.pendantTitle, - // 'pr_info': instance.prInfo, + 'pr_info': instance.prInfo, 'relation': instance.relation, 'is_deleted': instance.isDeleted, 'honours': instance.honours, diff --git a/lib/models/space/pr_info.dart b/lib/models/space/pr_info.dart index 403cddf7..f47ad1af 100644 --- a/lib/models/space/pr_info.dart +++ b/lib/models/space/pr_info.dart @@ -1,14 +1,34 @@ - class PrInfo { - PrInfo(); + PrInfo( + this.content, + this.url, + this.icon, + this.iconNight, + this.textColor, + this.bgColor, + this.textColorNight, + this.bgColorNight, + ); - factory PrInfo.fromJson(Map json) { - // TODO: implement fromJson - throw UnimplementedError('PrInfo.fromJson($json) is not implemented'); - } + String? content; + String? url; + String? icon; + String? iconNight; + String? textColor; + String? bgColor; + String? textColorNight; + String? bgColorNight; - Map toJson() { - // TODO: implement toJson - throw UnimplementedError(); - } -} \ No newline at end of file + PrInfo.fromJson(Map json) { + content = json['content']; + if (content?.isNotEmpty == true) { + url = json['url']; + icon = json['icon']; + iconNight = json['icon_night']; + textColor = json['text_color'] ?? "#999999"; + bgColor = json['bg_color'] ?? "#e7e7e7"; + textColorNight = json['text_color_night'] ?? "#727272"; + bgColorNight = json['bg_color_night'] ?? "#2A2A2A"; + } + } +} diff --git a/lib/pages/member/new/widget/user_info_card.dart b/lib/pages/member/new/widget/user_info_card.dart index 30432a6d..8acc851e 100644 --- a/lib/pages/member/new/widget/user_info_card.dart +++ b/lib/pages/member/new/widget/user_info_card.dart @@ -535,6 +535,66 @@ class UserInfoCard extends StatelessWidget { ], ), ..._buildLeft(context), + if (card.prInfo?.content?.isNotEmpty == true) + Builder(builder: (context) { + final isDark = Theme.of(context).brightness == Brightness.dark; + final textColor = isDark + ? Color(int.parse( + 'FF${card.prInfo?.textColorNight?.substring(1)}', + radix: 16)) + : Color(int.parse('FF${card.prInfo?.textColor?.substring(1)}', + radix: 16)); + return GestureDetector( + onTap: () { + if (card.prInfo?.url?.isNotEmpty == true) { + Utils.handleWebview(card.prInfo!.url!); + } + }, + child: Container( + margin: const EdgeInsets.only(top: 8), + padding: + const EdgeInsets.symmetric(horizontal: 16, vertical: 10), + color: isDark + ? Color(int.parse( + 'FF${card.prInfo?.bgColorNight?.substring(1)}', + radix: 16)) + : Color(int.parse( + 'FF${card.prInfo?.bgColor?.substring(1)}', + radix: 16)), + child: Row( + children: [ + if (isDark && + card.prInfo?.iconNight?.isNotEmpty == true) ...[ + CachedNetworkImage( + imageUrl: card.prInfo!.iconNight!, + height: 20, + ), + const SizedBox(width: 16), + ] else if (card.prInfo?.icon?.isNotEmpty == true) ...[ + CachedNetworkImage( + imageUrl: card.prInfo!.icon!, + height: 20, + ), + const SizedBox(width: 16), + ], + Expanded( + child: Text( + card.prInfo!.content!, + style: TextStyle(fontSize: 15, color: textColor), + ), + ), + if (card.prInfo?.url?.isNotEmpty == true) ...[ + const SizedBox(width: 10), + Icon( + Icons.keyboard_arrow_right, + color: textColor, + ), + ], + ], + ), + ), + ); + }), const SizedBox(height: 5), ], );