From 381a44de4ce1dc7243c11a94e8e9d1f15b2854d4 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Thu, 26 Sep 2024 15:37:02 +0800 Subject: [PATCH] mod: show tag on dynamic panel --- lib/models/dynamics/result.dart | 18 ++++++++-- lib/pages/dynamics/detail/view.dart | 5 ++- lib/pages/dynamics/widgets/author_panel.dart | 33 ++++++++++++++++++- lib/pages/dynamics/widgets/dynamic_panel.dart | 2 +- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/lib/models/dynamics/result.dart b/lib/models/dynamics/result.dart index a7b92a62..d532881e 100644 --- a/lib/models/dynamics/result.dart +++ b/lib/models/dynamics/result.dart @@ -85,7 +85,7 @@ class ItemModulesModel { ModuleDynamicModel? moduleDynamic; // ModuleInterModel? moduleInter; ModuleStatModel? moduleStat; - Map? moduleTag; + ModuleTag? moduleTag; ItemModulesModel.fromJson(Map json) { moduleAuthor = json['module_author'] != null @@ -98,7 +98,9 @@ class ItemModulesModel { moduleStat = json['module_stat'] != null ? ModuleStatModel.fromJson(json['module_stat']) : null; - moduleTag = json['module_tag']; + moduleTag = json['module_tag'] != null + ? ModuleTag.fromJson(json['module_tag']) + : null; } } @@ -759,6 +761,18 @@ class DynamicLive2Model { } } +class ModuleTag { + ModuleTag({ + this.text, + }); + + String? text; + + ModuleTag.fromJson(Map json) { + text = json['text']; + } +} + // 动态状态 转发、评论、点赞 class ModuleStatModel { ModuleStatModel({ diff --git a/lib/pages/dynamics/detail/view.dart b/lib/pages/dynamics/detail/view.dart index 58364c04..1c734f6c 100644 --- a/lib/pages/dynamics/detail/view.dart +++ b/lib/pages/dynamics/detail/view.dart @@ -200,7 +200,10 @@ class _DynamicDetailPageState extends State return AnimatedOpacity( opacity: snapshot.data ? 1 : 0, duration: const Duration(milliseconds: 300), - child: AuthorPanel(item: _dynamicDetailController.item), + child: AuthorPanel( + item: _dynamicDetailController.item, + source: 'detail', //to remove tag + ), ); }, ), diff --git a/lib/pages/dynamics/widgets/author_panel.dart b/lib/pages/dynamics/widgets/author_panel.dart index 31e062a0..6e5c41fd 100644 --- a/lib/pages/dynamics/widgets/author_panel.dart +++ b/lib/pages/dynamics/widgets/author_panel.dart @@ -13,7 +13,13 @@ import '../controller.dart'; class AuthorPanel extends StatelessWidget { final dynamic item; final Function? addBannedList; - const AuthorPanel({super.key, required this.item, this.addBannedList}); + final String? source; + const AuthorPanel({ + super.key, + required this.item, + this.addBannedList, + this.source, + }); @override Widget build(BuildContext context) { @@ -82,6 +88,31 @@ class AuthorPanel extends StatelessWidget { ], ), const Spacer(), + if (source != 'detail' && item.modules?.moduleTag?.text != null) + Container( + padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2), + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.surface, + borderRadius: const BorderRadius.all(Radius.circular(4)), + border: Border.all( + width: 1.25, + color: Theme.of(context).colorScheme.primary, + ), + ), + child: Text( + item.modules.moduleTag.text, + style: TextStyle( + height: 1, + fontSize: 12, + color: Theme.of(context).colorScheme.primary, + ), + strutStyle: const StrutStyle( + leading: 0, + height: 1, + fontSize: 12, + ), + ), + ), SizedBox( width: 32, height: 32, diff --git a/lib/pages/dynamics/widgets/dynamic_panel.dart b/lib/pages/dynamics/widgets/dynamic_panel.dart index c526af20..a39f4d73 100644 --- a/lib/pages/dynamics/widgets/dynamic_panel.dart +++ b/lib/pages/dynamics/widgets/dynamic_panel.dart @@ -42,7 +42,7 @@ class DynamicPanel extends StatelessWidget { children: [ Padding( padding: const EdgeInsets.fromLTRB(12, 12, 12, 6), - child: AuthorPanel(item: item), + child: AuthorPanel(item: item, source: source), ), if (item!.modules!.moduleDynamic!.desc != null || item!.modules!.moduleDynamic!.major != null)