From 321b7933d76fd851adee73c59b8b6507eb442dce Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Fri, 3 Jan 2025 21:23:55 +0800 Subject: [PATCH] opt: code Signed-off-by: bggRGjQaUbCoE --- ...tom_sliver_persistent_header_delegate.dart | 9 +- lib/models/common/dynamics_type.dart | 64 +++++------ lib/models/common/nav_bar_config.dart | 82 +++++++------- lib/models/common/tab_type.dart | 104 +++++++++--------- lib/pages/dynamics/detail/view.dart | 2 +- .../content/video/member_video.dart | 2 +- .../search_panel/widgets/article_panel.dart | 2 +- .../search_panel/widgets/user_panel.dart | 2 +- .../search_panel/widgets/video_panel.dart | 2 +- .../detail/member/horizontal_member_page.dart | 2 +- lib/pages/video/detail/reply/view.dart | 2 +- 11 files changed, 139 insertions(+), 134 deletions(-) diff --git a/lib/common/widgets/custom_sliver_persistent_header_delegate.dart b/lib/common/widgets/custom_sliver_persistent_header_delegate.dart index 492403cf..fb7b6f69 100644 --- a/lib/common/widgets/custom_sliver_persistent_header_delegate.dart +++ b/lib/common/widgets/custom_sliver_persistent_header_delegate.dart @@ -4,12 +4,14 @@ class CustomSliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate { CustomSliverPersistentHeaderDelegate({ required this.child, + required this.bgColor, double extent = 45, }) : _minExtent = extent, _maxExtent = extent; final double _minExtent; final double _maxExtent; final Widget child; + final Color bgColor; @override Widget build( @@ -17,7 +19,10 @@ class CustomSliverPersistentHeaderDelegate //创建child子组件 //shrinkOffset:child偏移值minExtent~maxExtent //overlapsContent:SliverPersistentHeader覆盖其他子组件返回true,否则返回false - return child; + return ColoredBox( + color: bgColor, + child: child, + ); } //SliverPersistentHeader最大高度 @@ -31,6 +36,6 @@ class CustomSliverPersistentHeaderDelegate @override bool shouldRebuild( covariant CustomSliverPersistentHeaderDelegate oldDelegate) { - return true; + return oldDelegate.bgColor != bgColor; } } diff --git a/lib/models/common/dynamics_type.dart b/lib/models/common/dynamics_type.dart index 59d0cf2f..0de2c003 100644 --- a/lib/models/common/dynamics_type.dart +++ b/lib/models/common/dynamics_type.dart @@ -11,35 +11,35 @@ extension BusinessTypeExtension on DynamicsType { String get labels => ['全部', '投稿', '番剧', '专栏', 'UP'][index]; } -List tabsConfig = [ - { - 'tag': 'all', - 'value': DynamicsType.all, - 'label': '全部', - 'enabled': true, - }, - { - 'tag': 'video', - 'value': DynamicsType.video, - 'label': '投稿', - 'enabled': true, - }, - { - 'tag': 'pgc', - 'value': DynamicsType.pgc, - 'label': '番剧', - 'enabled': true, - }, - { - 'tag': 'article', - 'value': DynamicsType.article, - 'label': '专栏', - 'enabled': true, - }, - { - 'tag': 'up', - 'value': DynamicsType.up, - 'label': 'UP', - 'enabled': true, - }, -]; +List get tabsConfig => [ + { + 'tag': 'all', + 'value': DynamicsType.all, + 'label': '全部', + 'enabled': true, + }, + { + 'tag': 'video', + 'value': DynamicsType.video, + 'label': '投稿', + 'enabled': true, + }, + { + 'tag': 'pgc', + 'value': DynamicsType.pgc, + 'label': '番剧', + 'enabled': true, + }, + { + 'tag': 'article', + 'value': DynamicsType.article, + 'label': '专栏', + 'enabled': true, + }, + { + 'tag': 'up', + 'value': DynamicsType.up, + 'label': 'UP', + 'enabled': true, + }, + ]; diff --git a/lib/models/common/nav_bar_config.dart b/lib/models/common/nav_bar_config.dart index 988b02ce..73b1c20f 100644 --- a/lib/models/common/nav_bar_config.dart +++ b/lib/models/common/nav_bar_config.dart @@ -1,43 +1,43 @@ import 'package:flutter/material.dart'; -List defaultNavigationBars = [ - { - 'id': 0, - 'icon': const Icon( - Icons.home_outlined, - size: 23, - ), - 'selectIcon': const Icon( - Icons.home, - size: 23, - ), - 'label': "首页", - 'count': 0, - }, - { - 'id': 1, - 'icon': const Icon( - Icons.motion_photos_on_outlined, - size: 21, - ), - 'selectIcon': const Icon( - Icons.motion_photos_on, - size: 21, - ), - 'label': "动态", - 'count': 0, - }, - { - 'id': 2, - 'icon': const Icon( - Icons.video_collection_outlined, - size: 21, - ), - 'selectIcon': const Icon( - Icons.video_collection, - size: 21, - ), - 'label': "媒体库", - 'count': 0, - } -]; +List get defaultNavigationBars => [ + { + 'id': 0, + 'icon': const Icon( + Icons.home_outlined, + size: 23, + ), + 'selectIcon': const Icon( + Icons.home, + size: 23, + ), + 'label': "首页", + 'count': 0, + }, + { + 'id': 1, + 'icon': const Icon( + Icons.motion_photos_on_outlined, + size: 21, + ), + 'selectIcon': const Icon( + Icons.motion_photos_on, + size: 21, + ), + 'label': "动态", + 'count': 0, + }, + { + 'id': 2, + 'icon': const Icon( + Icons.video_collection_outlined, + size: 21, + ), + 'selectIcon': const Icon( + Icons.video_collection, + size: 21, + ), + 'label': "媒体库", + 'count': 0, + } + ]; diff --git a/lib/models/common/tab_type.dart b/lib/models/common/tab_type.dart index 15705d30..420d6033 100644 --- a/lib/models/common/tab_type.dart +++ b/lib/models/common/tab_type.dart @@ -13,55 +13,55 @@ extension TabTypeDesc on TabType { String get id => ['live', 'rcmd', 'hot', 'rank', 'bangumi'][index]; } -List tabsConfig = [ - { - 'icon': const Icon( - Icons.live_tv_outlined, - size: 15, - ), - 'label': '直播', - 'type': TabType.live, - 'ctr': Get.find, - 'page': const RcmdPage(tabType: TabType.live), - }, - { - 'icon': const Icon( - Icons.thumb_up_off_alt_outlined, - size: 15, - ), - 'label': '推荐', - 'type': TabType.rcmd, - 'ctr': Get.find, - 'page': const RcmdPage(tabType: TabType.rcmd), - }, - { - 'icon': const Icon( - Icons.whatshot_outlined, - size: 15, - ), - 'label': '热门', - 'type': TabType.hot, - 'ctr': Get.find, - 'page': const HotPage(), - }, - { - 'icon': const Icon( - Icons.category_outlined, - size: 15, - ), - 'label': '分区', - 'type': TabType.rank, - 'ctr': Get.find, - 'page': const RankPage(), - }, - { - 'icon': const Icon( - Icons.play_circle_outlined, - size: 15, - ), - 'label': '番剧', - 'type': TabType.bangumi, - 'ctr': Get.find, - 'page': const BangumiPage(), - }, -]; +List get tabsConfig => [ + { + 'icon': const Icon( + Icons.live_tv_outlined, + size: 15, + ), + 'label': '直播', + 'type': TabType.live, + 'ctr': Get.find, + 'page': const RcmdPage(tabType: TabType.live), + }, + { + 'icon': const Icon( + Icons.thumb_up_off_alt_outlined, + size: 15, + ), + 'label': '推荐', + 'type': TabType.rcmd, + 'ctr': Get.find, + 'page': const RcmdPage(tabType: TabType.rcmd), + }, + { + 'icon': const Icon( + Icons.whatshot_outlined, + size: 15, + ), + 'label': '热门', + 'type': TabType.hot, + 'ctr': Get.find, + 'page': const HotPage(), + }, + { + 'icon': const Icon( + Icons.category_outlined, + size: 15, + ), + 'label': '分区', + 'type': TabType.rank, + 'ctr': Get.find, + 'page': const RankPage(), + }, + { + 'icon': const Icon( + Icons.play_circle_outlined, + size: 15, + ), + 'label': '番剧', + 'type': TabType.bangumi, + 'ctr': Get.find, + 'page': const BangumiPage(), + }, + ]; diff --git a/lib/pages/dynamics/detail/view.dart b/lib/pages/dynamics/detail/view.dart index 09f7ca09..7efbad2a 100644 --- a/lib/pages/dynamics/detail/view.dart +++ b/lib/pages/dynamics/detail/view.dart @@ -400,8 +400,8 @@ class _DynamicDetailPageState extends State SliverPersistentHeader replyPersistentHeader(BuildContext context) { return SliverPersistentHeader( delegate: CustomSliverPersistentHeaderDelegate( + bgColor: Theme.of(context).colorScheme.surface, child: Container( - color: Theme.of(context).colorScheme.surface, height: 45, padding: const EdgeInsets.only(left: 12, right: 6), child: Row( diff --git a/lib/pages/member/new/content/member_contribute/content/video/member_video.dart b/lib/pages/member/new/content/member_contribute/content/video/member_video.dart index d3d3a48e..248dc446 100644 --- a/lib/pages/member/new/content/member_contribute/content/video/member_video.dart +++ b/lib/pages/member/new/content/member_contribute/content/video/member_video.dart @@ -73,10 +73,10 @@ class _MemberVideoState extends State floating: true, delegate: CustomSliverPersistentHeaderDelegate( extent: 40, + bgColor: Theme.of(context).colorScheme.surface, child: Container( height: 40, padding: const EdgeInsets.fromLTRB(12, 0, 6, 0), - color: Theme.of(context).colorScheme.surface, child: Row( children: [ Obx( diff --git a/lib/pages/search_panel/widgets/article_panel.dart b/lib/pages/search_panel/widgets/article_panel.dart index 040d5428..d0920df8 100644 --- a/lib/pages/search_panel/widgets/article_panel.dart +++ b/lib/pages/search_panel/widgets/article_panel.dart @@ -28,9 +28,9 @@ Widget searchArticlePanel(context, searchPanelCtr, LoadingState loadingState) { floating: true, delegate: CustomSliverPersistentHeaderDelegate( extent: 40, + bgColor: Theme.of(context).colorScheme.surface, child: Container( height: 40, - color: Theme.of(context).colorScheme.surface, padding: const EdgeInsets.only(left: 25, right: 12), child: Row( children: [ diff --git a/lib/pages/search_panel/widgets/user_panel.dart b/lib/pages/search_panel/widgets/user_panel.dart index 5c8b2cce..961cd849 100644 --- a/lib/pages/search_panel/widgets/user_panel.dart +++ b/lib/pages/search_panel/widgets/user_panel.dart @@ -26,9 +26,9 @@ Widget searchUserPanel(context, searchPanelCtr, LoadingState loadingState) { floating: true, delegate: CustomSliverPersistentHeaderDelegate( extent: 40, + bgColor: Theme.of(context).colorScheme.surface, child: Container( height: 40, - color: Theme.of(context).colorScheme.surface, padding: const EdgeInsets.only(left: 25, right: 12), child: Row( children: [ diff --git a/lib/pages/search_panel/widgets/video_panel.dart b/lib/pages/search_panel/widgets/video_panel.dart index f54cccfb..8178156c 100644 --- a/lib/pages/search_panel/widgets/video_panel.dart +++ b/lib/pages/search_panel/widgets/video_panel.dart @@ -24,9 +24,9 @@ Widget searchVideoPanel(context, ctr, LoadingState loadingState) { floating: true, delegate: CustomSliverPersistentHeaderDelegate( extent: 34, + bgColor: Theme.of(context).colorScheme.surface, child: Container( height: 34, - color: Theme.of(context).colorScheme.surface, padding: const EdgeInsets.symmetric(horizontal: 12), child: Row( children: [ diff --git a/lib/pages/video/detail/member/horizontal_member_page.dart b/lib/pages/video/detail/member/horizontal_member_page.dart index 1c23173c..928df932 100644 --- a/lib/pages/video/detail/member/horizontal_member_page.dart +++ b/lib/pages/video/detail/member/horizontal_member_page.dart @@ -112,10 +112,10 @@ class _HorizontalMemberPageState extends State { floating: true, delegate: CustomSliverPersistentHeaderDelegate( extent: 40, + bgColor: Theme.of(context).colorScheme.surface, child: Container( height: 40, padding: const EdgeInsets.fromLTRB(12, 0, 6, 0), - color: Theme.of(context).colorScheme.surface, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ diff --git a/lib/pages/video/detail/reply/view.dart b/lib/pages/video/detail/reply/view.dart index 908620df..f197876a 100644 --- a/lib/pages/video/detail/reply/view.dart +++ b/lib/pages/video/detail/reply/view.dart @@ -134,10 +134,10 @@ class _VideoReplyPanelState extends State floating: true, delegate: CustomSliverPersistentHeaderDelegate( extent: 40, + bgColor: Theme.of(context).colorScheme.surface, child: Container( height: 40, padding: const EdgeInsets.fromLTRB(12, 0, 6, 0), - color: Theme.of(context).colorScheme.surface, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [