基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
fix(timeline): align card covers
Predidit99562de8aed4
diff --git a/lib/bean/card/bangumi_timeline_card.dart b/lib/bean/card/bangumi_timeline_card.dartindex 8973f9c6..cc05ab11 100644--- a/lib/bean/card/bangumi_timeline_card.dart+++ b/lib/bean/card/bangumi_timeline_card.dart@@ -1,3 +1,5 @@+import 'dart:math' as math;+import 'package:flutter/material.dart';import 'package:kazumi/bean/card/network_img_layer.dart';import 'package:kazumi/modules/bangumi/bangumi_item.dart';@@ -21,20 +23,40 @@ class BangumiTimelineCard extends StatelessWidget {static final _episodePattern =RegExp(r'^\s*([1-9]\d*)\s*[话話集](?=\s*(?:[//]|$))');- static double heightFor(TextScaler scaler, {bool compact = false}) =>- (compact ? 48 : 64) +- scaler.scale(22) * 2 +- scaler.scale(18) +- scaler.scale(20);+ static const _contentPadding = 12.0;+ static const _cornerRadius = 28.0;+ static const _titleFontSize = 16.0;+ static const _titleLineHeight = 1.5;+ static const _labelFontSize = 12.0;+ static const _labelLineHeight = 4 / 3;+ static const _metadataGap = 8.0;+ static const _footerGap = 12.0;+ static const _ratingIconSize = 16.0;+ static const _ratingPadding =+ EdgeInsets.symmetric(horizontal: 10, vertical: 6);++ // Shared by the grid and card to keep their text-scaled heights in sync.+ static double heightFor(TextScaler scaler, {bool compact = false}) {+ final titleHeight = scaler.scale(_titleFontSize) * _titleLineHeight * 2;+ final labelHeight = scaler.scale(_labelFontSize) * _labelLineHeight;+ final footerHeight =+ math.max(_ratingIconSize, labelHeight) + _ratingPadding.vertical;+ final contentHeight = math.max(+ compact ? 120.0 : 136.0,+ titleHeight + _metadataGap + labelHeight + _footerGap + footerHeight,+ );+ return _contentPadding * 2 + contentHeight;+ }String _supportingText(String title) {- // Calendar subjects provide episodes in `info`, but no separate air date.+ // Calendar entries expose episode counts through info.final episodes = _episodePattern.firstMatch(bangumiItem.info);+ final tags = bangumiItem.metaTags.isNotEmpty+ ? bangumiItem.metaTags+ : bangumiItem.tags.map((tag) => tag.name);final metadata = <String>[if (episodes != null) '${episodes.group(1)} 话',- ...(bangumiItem.metaTags.isNotEmpty- ? bangumiItem.metaTags- : bangumiItem.tags.map((tag) => tag.name))+ ...tags.map((name) => name.trim()).where((name) => name.isNotEmpty).toSet(),@@ -46,21 +68,15 @@ class BangumiTimelineCard extends StatelessWidget {@overrideWidget build(BuildContext context) {- final theme = Theme.of(context);- final colors = theme.colorScheme;- final translatedName = bangumiItem.nameCn.trim();- final title =- translatedName.isNotEmpty ? translatedName : bangumiItem.name.trim();- final supportingText = _supportingText(title);- final radius = BorderRadius.all(Radius.circular(compact ? 20 : 24));-return Semantics(button: true,child: Card(elevation: 0,margin: EdgeInsets.zero,- color: colors.surfaceContainerLow,- shape: RoundedRectangleBorder(borderRadius: radius),+ color: Theme.of(context).colorScheme.surfaceContainerLow,+ shape: const RoundedRectangleBorder(+ borderRadius: BorderRadius.all(Radius.circular(_cornerRadius)),+ ),clipBehavior: Clip.antiAlias,child: InkWell(onTap: onTap,@@ -68,67 +84,13 @@ class BangumiTimelineCard extends StatelessWidget {height:heightFor(MediaQuery.textScalerOf(context), compact: compact),child: Padding(- padding: const EdgeInsets.all(12),+ padding: const EdgeInsets.all(_contentPadding),child: Row(- crossAxisAlignment: CrossAxisAlignment.start,+ crossAxisAlignment: CrossAxisAlignment.stretch,children: [_buildCover(context),SizedBox(width: compact ? 12 : 16),- Expanded(- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Text(- title,- maxLines: 2,- overflow: TextOverflow.ellipsis,- style: theme.textTheme.titleMedium?.copyWith(- color: colors.onSurface,- fontWeight: FontWeight.w600,- height: 1.375,- ),- ),- const Spacer(),- if (supportingText.isNotEmpty) ...[- Text(- supportingText,- maxLines: 1,- overflow: TextOverflow.ellipsis,- style: theme.textTheme.bodySmall?.copyWith(- color: colors.onSurfaceVariant,- ),- ),- const SizedBox(height: 8),- ],- Row(- children: [- if (showRating)- Expanded(- child: Align(- alignment: Alignment.centerLeft,- child: _buildRating(context),- ),- )- else- const Spacer(),- if (isWatching) ...[- if (showRating) const SizedBox(width: 8),- Tooltip(- message: '正在追',- child: Icon(Icons.bookmark_rounded,- size: 20,- color: colors.primary,- semanticLabel: '正在追'),- ),- ],- const SizedBox(width: 8),- Icon(Icons.chevron_right_rounded,- size: 20, color: colors.onSurfaceVariant),- ],- ),- ],- ),- ),+ Expanded(child: _buildDetails(context)),],),),@@ -138,30 +100,99 @@ class BangumiTimelineCard extends StatelessWidget {);}+ Widget _buildDetails(BuildContext context) {+ final theme = Theme.of(context);+ final colors = theme.colorScheme;+ final translatedName = bangumiItem.nameCn.trim();+ final title =+ translatedName.isNotEmpty ? translatedName : bangumiItem.name.trim();+ final supportingText = _supportingText(title);++ return Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(+ title,+ maxLines: 2,+ overflow: TextOverflow.ellipsis,+ style: theme.textTheme.titleMedium?.copyWith(+ color: colors.onSurface,+ fontSize: _titleFontSize,+ fontWeight: FontWeight.w700,+ height: _titleLineHeight,+ ),+ ),+ if (supportingText.isNotEmpty) ...[+ const SizedBox(height: _metadataGap),+ Text(+ supportingText,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ style: theme.textTheme.bodySmall?.copyWith(+ color: colors.onSurfaceVariant,+ fontSize: _labelFontSize,+ height: _labelLineHeight,+ ),+ ),+ ],+ if (showRating || isWatching) ...[+ const Spacer(),+ const SizedBox(height: _footerGap),+ Row(+ children: [+ if (showRating)+ Expanded(+ child: Align(+ alignment: Alignment.centerLeft,+ child: _buildRating(context),+ ),+ )+ else+ const Spacer(),+ if (isWatching) ...[+ if (showRating) const SizedBox(width: 8),+ Tooltip(+ message: '正在追',+ child: Icon(Icons.bookmark_rounded,+ size: 20, color: colors.primary),+ ),+ ],+ ],+ ),+ ],+ ],+ );+ }+Widget _buildCover(BuildContext context) {final colors = Theme.of(context).colorScheme;final imageUrl = bangumiItem.images['large'] ?? '';- final width = compact ? 68.0 : 80.0;- final height = compact ? 96.0 : 112.0;- final cover = ClipRRect(- borderRadius: BorderRadius.circular(16),- child: imageUrl.isEmpty- ? ColoredBox(- color: colors.surfaceContainerHighest,- child: SizedBox(- width: width,- height: height,- child:- Icon(Icons.movie_outlined, color: colors.onSurfaceVariant),- ),- )- : NetworkImgLayer(src: imageUrl, width: width, height: height),- );return ExcludeSemantics(- child: Hero(- tag: bangumiItem.id,- transitionOnUserGestures: true,- child: cover,+ child: SizedBox(+ width: compact ? 80 : 88,+ child: LayoutBuilder(+ builder: (context, constraints) => Hero(+ tag: bangumiItem.id,+ transitionOnUserGestures: true,+ child: ClipRRect(+ borderRadius: const BorderRadius.all(+ Radius.circular(_cornerRadius - _contentPadding)),+ child: imageUrl.isEmpty+ ? ColoredBox(+ color: colors.surfaceContainerHighest,+ child: Center(+ child: Icon(Icons.movie_outlined,+ color: colors.onSurfaceVariant),+ ),+ )+ : NetworkImgLayer(+ src: imageUrl,+ width: constraints.maxWidth,+ height: constraints.maxHeight,+ ),+ ),+ ),+ ),),);}@@ -169,33 +200,36 @@ class BangumiTimelineCard extends StatelessWidget {Widget _buildRating(BuildContext context) {final theme = Theme.of(context);final colors = theme.colorScheme;+ final labelStyle = theme.textTheme.labelMedium?.copyWith(+ fontSize: _labelFontSize,+ height: _labelLineHeight,+ );if (bangumiItem.ratingScore <= 0) {return Text('暂无评分',maxLines: 1,overflow: TextOverflow.ellipsis,- style: theme.textTheme.labelMedium- ?.copyWith(color: colors.onSurfaceVariant));+ style: labelStyle?.copyWith(color: colors.onSurfaceVariant));}final score = bangumiItem.ratingScore.toStringAsFixed(1);return Semantics(label: '评分 $score',excludeSemantics: true,child: Container(- padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),- decoration: BoxDecoration(+ padding: _ratingPadding,+ decoration: ShapeDecoration(color: colors.secondaryContainer,- borderRadius: BorderRadius.circular(8),+ shape: const StadiumBorder(),),child: Row(mainAxisSize: MainAxisSize.min,children: [Icon(Icons.star_rounded,- size: 14, color: colors.onSecondaryContainer),+ size: _ratingIconSize, color: colors.onSecondaryContainer),const SizedBox(width: 4),Flexible(child: Text(score,maxLines: 1,- style: theme.textTheme.labelMedium?.copyWith(+ style: labelStyle?.copyWith(color: colors.onSecondaryContainer,fontWeight: FontWeight.w700,)),