Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

refactor(timeline): migrate bangumi timeline card to material 3 style and simplify hierarchy

Predidit54dc4e766320
diff --git a/lib/bean/card/bangumi_timeline_card.dart b/lib/bean/card/bangumi_timeline_card.dart
index c51d84e2..45fe440f 100644
--- a/lib/bean/card/bangumi_timeline_card.dart
+++ b/lib/bean/card/bangumi_timeline_card.dart
@@ -29,17 +29,23 @@ class BangumiTimelineCard extends StatelessWidget {
final isTablet = Utils.isTablet();
final theme = Theme.of(context);
final textScaler = MediaQuery.textScalerOf(context);
- final double imageWidth = cardHeight * 0.7;
- final double borderRadius = 18;
+ final colorScheme = theme.colorScheme;
+ const double borderRadius = 16;
+ const double horizontalPadding = 12;
+ const double verticalPadding = 10;
+ final double contentHeight = cardHeight > verticalPadding * 2
+ ? cardHeight - (verticalPadding * 2)
+ : cardHeight;
+ final double imageWidth = contentHeight * 0.7;
return Card(
- elevation: 1,
- margin: const EdgeInsets.symmetric(vertical: 4, horizontal: 6),
+ elevation: 0,
+ margin: const EdgeInsets.symmetric(vertical: 4),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(borderRadius),
),
clipBehavior: Clip.antiAlias,
- color: theme.colorScheme.surface,
+ color: colorScheme.surfaceContainerLow,
child: InkWell(
borderRadius: BorderRadius.circular(borderRadius),
onTap: onTap ??
@@ -49,26 +55,35 @@ class BangumiTimelineCard extends StatelessWidget {
child: SizedBox(
height: cardHeight,
width: cardWidth,
- child: Row(
- crossAxisAlignment: CrossAxisAlignment.stretch,
- children: [
- buildImage(context, bangumiItem.images['large'] ?? '', imageWidth, cardHeight),
- Expanded(
- child: Padding(
- padding:
- const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(
+ horizontal: horizontalPadding,
+ vertical: verticalPadding,
+ ),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ buildImage(
+ context,
+ bangumiItem.images['large'] ?? '',
+ imageWidth,
+ contentHeight,
+ ),
+ const SizedBox(width: 12),
+ Expanded(
child: buildInfo(context, textScaler, isDesktop, isTablet),
),
- ),
- ],
+ ],
+ ),
),
),
),
);
}
- Widget buildImage(BuildContext context, String imageUrl, double width, double height) {
- final borderRadius = BorderRadius.circular(16);
+ Widget buildImage(
+ BuildContext context, String imageUrl, double width, double height) {
+ final borderRadius = BorderRadius.circular(12);
Widget img = NetworkImgLayer(
src: imageUrl,
width: width,
@@ -96,89 +111,112 @@ class BangumiTimelineCard extends StatelessWidget {
bool isTablet) {
final theme = Theme.of(context);
final colorScheme = theme.colorScheme;
- final nameStyle =
- theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w600);
- final subStyle = theme.textTheme.bodySmall
- ?.copyWith(color: colorScheme.onSurfaceVariant);
- final infoStyle =
- theme.textTheme.bodySmall?.copyWith(fontWeight: FontWeight.w500);
- final maxLines = isDesktop ? 2 : 1;
- final double spacing = isDesktop ? 8 : 4;
+ final title =
+ bangumiItem.nameCn.isNotEmpty ? bangumiItem.nameCn : bangumiItem.name;
+ final supportingText = bangumiItem.info.trim().isNotEmpty
+ ? bangumiItem.info.trim()
+ : bangumiItem.summary.trim();
+ final bool useWideLayout = isDesktop || isTablet;
+ final int supportingLines = useWideLayout ? 3 : 2;
+ final nameStyle = theme.textTheme.titleSmall?.copyWith(
+ color: colorScheme.onSurface,
+ fontWeight: FontWeight.w600,
+ height: 1.2,
+ );
+ final subStyle = theme.textTheme.bodySmall?.copyWith(
+ color: colorScheme.onSurfaceVariant,
+ height: 1.2,
+ );
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
- // 标题
Text(
- bangumiItem.nameCn.isNotEmpty ? bangumiItem.nameCn : bangumiItem.name,
+ title,
style: nameStyle,
- maxLines: maxLines,
+ maxLines: useWideLayout ? 2 : 1,
overflow: TextOverflow.ellipsis,
- textScaler: textScaler.clamp(maxScaleFactor: 1.1),
+ textScaler:
+ textScaler.clamp(maxScaleFactor: useWideLayout ? 1.2 : 1.1),
),
- SizedBox(height: spacing),
- // 简介
- if (bangumiItem.summary.isNotEmpty || bangumiItem.info.isNotEmpty)
- Padding(
- padding: const EdgeInsets.only(bottom: 2),
- child: DecoratedBox(
- decoration: BoxDecoration(
- color: colorScheme.primaryContainer.withAlpha((255 * 0.10).round()),
- borderRadius: BorderRadius.circular(6),
- ),
- child: Padding(
- padding: const EdgeInsets.only(bottom: 2),
- child: Text(
- bangumiItem.info.isNotEmpty
- ? bangumiItem.info
- : bangumiItem.summary,
- style: theme.textTheme.labelMedium?.copyWith(
- color: colorScheme.primary,
- fontWeight: FontWeight.w500,
- ),
- maxLines: 3,
- overflow: TextOverflow.ellipsis,
- textScaler: textScaler.clamp(maxScaleFactor: 1.0),
- ),
- ),
- ),
+ Expanded(
+ child: Padding(
+ padding: EdgeInsets.only(top: supportingText.isNotEmpty ? 6 : 0),
+ child: supportingText.isNotEmpty
+ ? Text(
+ supportingText,
+ style: subStyle,
+ maxLines: supportingLines,
+ overflow: TextOverflow.ellipsis,
+ textScaler: textScaler.clamp(maxScaleFactor: 1.0),
+ )
+ : const SizedBox.shrink(),
),
- const Spacer(),
- Row(
- children: [
- if (showRating ? bangumiItem.ratingScore > 0 : true)
- Row(
- children: [
- Icon(Icons.star_rounded,
- size: 15, color: colorScheme.primary),
- const SizedBox(width: 2),
- Text(
- showRating
- ? bangumiItem.ratingScore.toStringAsFixed(1)
- : '***',
- style: infoStyle),
- ],
- ),
- if (showRating ? bangumiItem.rank > 0 : true)
- Padding(
- padding: const EdgeInsets.only(left: 8),
- child: Row(
- children: [
- Icon(Icons.leaderboard,
- size: 15, color: colorScheme.tertiary),
- const SizedBox(width: 2),
- Text(
- showRating ? 'Rank ${bangumiItem.rank}' : 'Rank ***',
- style: infoStyle),
- ],
- ),
- ),
- const Spacer(),
- if (showRating ? bangumiItem.votes > 0 : true)
- Text(
- showRating ? '评分人数: ${bangumiItem.votes}' : '评分人数: ***',
- style: subStyle),
- ],
),
+ const SizedBox(height: 8),
+ buildFooter(context),
+ ],
+ );
+ }
+
+ Widget buildFooter(BuildContext context) {
+ final theme = Theme.of(context);
+ final colorScheme = theme.colorScheme;
+ final metricStyle = theme.textTheme.labelMedium?.copyWith(
+ color: colorScheme.onSurface,
+ fontWeight: FontWeight.w600,
+ );
+ final showScore = showRating ? bangumiItem.ratingScore > 0 : true;
+ final showRank = showRating ? bangumiItem.rank > 0 : true;
+ final showVotes = showRating ? bangumiItem.votes > 0 : true;
+ final rankText = showRating ? '#${bangumiItem.rank}' : '#***';
+ final votesText = showRating ? bangumiItem.votes.toString() : '***';
+
+ return Wrap(
+ spacing: 8,
+ runSpacing: 4,
+ children: [
+ if (showScore)
+ buildMetric(
+ context,
+ icon: Icons.star_rounded,
+ iconColor: colorScheme.primary,
+ label:
+ showRating ? bangumiItem.ratingScore.toStringAsFixed(1) : '***',
+ textStyle: metricStyle,
+ ),
+ if (showRank)
+ buildMetric(
+ context,
+ icon: Icons.leaderboard_outlined,
+ iconColor: colorScheme.secondary,
+ label: rankText,
+ textStyle: metricStyle,
+ ),
+ if (showVotes)
+ buildMetric(
+ context,
+ icon: Icons.how_to_vote_outlined,
+ iconColor: colorScheme.onSurfaceVariant,
+ label: votesText,
+ textStyle: metricStyle,
+ ),
+ ],
+ );
+ }
+
+ Widget buildMetric(
+ BuildContext context, {
+ required IconData icon,
+ required Color iconColor,
+ required String label,
+ required TextStyle? textStyle,
+ }) {
+ return Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(icon, size: 15, color: iconColor),
+ const SizedBox(width: 4),
+ Text(label, style: textStyle),
],
);
}
diff --git a/lib/pages/timeline/timeline_page.dart b/lib/pages/timeline/timeline_page.dart
index 6a8a3886..592664a8 100644
--- a/lib/pages/timeline/timeline_page.dart
+++ b/lib/pages/timeline/timeline_page.dart
@@ -568,23 +568,27 @@ class _TimelinePageState extends State<TimelinePage>
gridViewList.add(
CustomScrollView(
slivers: [
- SliverGrid(
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- mainAxisSpacing: StyleString.cardSpace - 2,
- crossAxisSpacing: StyleString.cardSpace,
- crossAxisCount: crossCount,
- mainAxisExtent: cardHeight + 12,
- ),
- delegate: SliverChildBuilderDelegate(
- (BuildContext context, int index) {
- if (filteredList.isEmpty) return null;
- final item = filteredList[index];
- return BangumiTimelineCard(
- bangumiItem: item,
- cardHeight: cardHeight,
- showRating: showRating);
- },
- childCount: filteredList.isNotEmpty ? filteredList.length : 10,
+ SliverPadding(
+ padding: const EdgeInsets.symmetric(horizontal: 8),
+ sliver: SliverGrid(
+ gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
+ mainAxisSpacing: StyleString.cardSpace - 2,
+ crossAxisSpacing: StyleString.cardSpace,
+ crossAxisCount: crossCount,
+ mainAxisExtent: cardHeight + 12,
+ ),
+ delegate: SliverChildBuilderDelegate(
+ (BuildContext context, int index) {
+ if (filteredList.isEmpty) return null;
+ final item = filteredList[index];
+ return BangumiTimelineCard(
+ bangumiItem: item,
+ cardHeight: cardHeight,
+ showRating: showRating);
+ },
+ childCount:
+ filteredList.isNotEmpty ? filteredList.length : 10,
+ ),
),
),
],