138 lines
4.7 KiB
Dart
138 lines
4.7 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/data/models/drama.dart';
|
|
import '../../../core/theme/app_colors.dart';
|
|
import '../../../core/theme/app_dimens.dart';
|
|
import '../../../core/widgets/app_press_scale.dart';
|
|
import '../../../core/widgets/cover_play_count.dart';
|
|
import '../../../core/widgets/drama_cover_badge_ribbon.dart';
|
|
import '../../../core/widgets/remote_image.dart';
|
|
|
|
final RegExp _tagSplitter = RegExp(r'[,/、·]');
|
|
|
|
class RecommendSectionCard extends StatelessWidget {
|
|
const RecommendSectionCard({
|
|
super.key,
|
|
required this.sectionKey,
|
|
required this.drama,
|
|
required this.onTap,
|
|
});
|
|
|
|
final String sectionKey;
|
|
final Drama drama;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final tagLabel = drama.localizedTag(
|
|
Localizations.localeOf(context).languageCode,
|
|
);
|
|
return AppPressScale(
|
|
child: SizedBox(
|
|
width: AppDimens.recommendCardWidth,
|
|
child: InkWell(
|
|
key: Key('recommend-card-$sectionKey-${drama.id}'),
|
|
borderRadius: BorderRadius.circular(AppDimens.cardCoverRadius),
|
|
onTap: onTap,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(AppDimens.cardCoverRadius),
|
|
child: AspectRatio(
|
|
aspectRatio: AppDimens.cardCoverAspectRatio,
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
RemoteImage(
|
|
drama.posterUrl,
|
|
fit: BoxFit.cover,
|
|
fallbackColor: AppColors.contentSurface,
|
|
),
|
|
if (tagLabel.isNotEmpty)
|
|
Positioned(
|
|
top: 0,
|
|
right: 0,
|
|
child: DramaCoverBadgeRibbon(
|
|
label: tagLabel,
|
|
color: drama.tagRibbonColor(AppColors.badgeHot),
|
|
keyPrefix: '$sectionKey-${drama.id}-tag',
|
|
),
|
|
),
|
|
const Positioned(
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
child: CoverBottomScrim(),
|
|
),
|
|
Positioned(
|
|
right: AppDimens.cardPlayCountRight,
|
|
bottom: AppDimens.cardPlayCountBottom,
|
|
child: CoverPlayCount(
|
|
key: Key('recommend-views-$sectionKey-${drama.id}'),
|
|
count: drama.viewCount,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: AppDimens.cardCoverTitleGap),
|
|
Text(
|
|
drama.localizedTitle(
|
|
Localizations.localeOf(context).languageCode,
|
|
),
|
|
key: Key('recommend-title-$sectionKey-${drama.id}'),
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
color: AppColors.textPrimary,
|
|
fontSize: AppDimens.cardTitleFont,
|
|
fontWeight: FontWeight.w500,
|
|
height: AppDimens.cardTitleLineHeight,
|
|
),
|
|
),
|
|
const SizedBox(height: AppDimens.cardTitleTagGap),
|
|
_tags(context),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _tags(BuildContext context) {
|
|
final tags = _cardTags(context);
|
|
if (tags.isEmpty) return const SizedBox.shrink();
|
|
return Text(
|
|
tags.join(' | '),
|
|
key: Key('recommend-tags-$sectionKey-${drama.id}'),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
textAlign: TextAlign.left,
|
|
style: const TextStyle(
|
|
color: AppColors.textTertiary,
|
|
fontSize: AppDimens.cardTagFont,
|
|
),
|
|
);
|
|
}
|
|
|
|
List<String> _cardTags(BuildContext context) {
|
|
final localized = drama.localizedTypeLabels(
|
|
Localizations.localeOf(context).languageCode,
|
|
);
|
|
if (localized.isNotEmpty) return localized.take(3).toList(growable: false);
|
|
final seen = <String>{};
|
|
return [drama.genre, drama.category]
|
|
.expand((value) => value.split(_tagSplitter))
|
|
.map((value) => value.trim())
|
|
.where((value) => value.isNotEmpty && seen.add(value))
|
|
.take(3)
|
|
.toList(growable: false);
|
|
}
|
|
}
|