287 lines
7.7 KiB
Dart
287 lines
7.7 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../core/config/app_config.dart';
|
|
import '../../../core/data/models/drama.dart';
|
|
import '../../../core/theme/app_colors.dart';
|
|
import '../../../core/theme/app_dimens.dart';
|
|
import '../../../core/theme/app_theme.dart';
|
|
import '../../../l10n/app_localizations.dart';
|
|
|
|
const int _columns = 2;
|
|
const double _columnGap = 10;
|
|
const double _cardGap = 10;
|
|
const double _addSize = 28;
|
|
const double _addIconSize = 18;
|
|
|
|
/// 剧场/分类页共用的双列剧目网格。
|
|
class DramaGrid extends StatelessWidget {
|
|
const DramaGrid({
|
|
super.key,
|
|
required this.l10n,
|
|
required this.dramas,
|
|
required this.onOpen,
|
|
});
|
|
|
|
final AppLocalizations l10n;
|
|
final List<Drama> dramas;
|
|
final ValueChanged<Drama> onOpen;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
key: const Key('home-all-dramas-section'),
|
|
padding: const EdgeInsets.symmetric(horizontal: 14),
|
|
child: Row(
|
|
key: const Key('home-all-dramas-grid'),
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Expanded(child: _column(0)),
|
|
const SizedBox(width: _columnGap),
|
|
Expanded(child: _column(1)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _column(int start) {
|
|
final children = <Widget>[];
|
|
for (var index = start; index < dramas.length; index += _columns) {
|
|
final drama = dramas[index];
|
|
children.add(
|
|
DramaGridCard(l10n: l10n, drama: drama, onTap: () => onOpen(drama)),
|
|
);
|
|
if (index + _columns < dramas.length) {
|
|
children.add(const SizedBox(height: _cardGap));
|
|
}
|
|
}
|
|
return Column(children: children);
|
|
}
|
|
}
|
|
|
|
/// 双列网格中的剧目卡片。
|
|
class DramaGridCard extends StatelessWidget {
|
|
const DramaGridCard({
|
|
super.key,
|
|
required this.l10n,
|
|
required this.drama,
|
|
required this.onTap,
|
|
});
|
|
|
|
final AppLocalizations l10n;
|
|
final Drama drama;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: AppColors.card,
|
|
borderRadius: BorderRadius.circular(AppDimens.cardRadius),
|
|
boxShadow: const [AppTheme.cardShadow],
|
|
),
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
borderRadius: BorderRadius.circular(AppDimens.cardRadius),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: InkWell(
|
|
key: Key('home-drama-card-${drama.id}'),
|
|
onTap: onTap,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(AppDimens.spaceSm),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_cover(),
|
|
const SizedBox(height: AppDimens.spaceSm),
|
|
_title(),
|
|
const SizedBox(height: AppDimens.spaceXs),
|
|
_footer(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _cover() {
|
|
final free =
|
|
drama.freeEpisodes > 0 ||
|
|
drama.episodes.any((episode) => episode.isFree);
|
|
return ClipRRect(
|
|
key: Key('home-drama-cover-${drama.id}'),
|
|
borderRadius: BorderRadius.circular(AppDimens.coverRadius),
|
|
child: Stack(
|
|
children: [
|
|
_DiscoverCoverImage(path: drama.posterUrl),
|
|
Positioned(top: 8, left: 8, child: _tagBadge(free)),
|
|
if (_lockedCount > 0)
|
|
Positioned(top: 8, right: 8, child: _lockedBadge()),
|
|
Positioned(right: 8, bottom: 8, child: _episodeBadge()),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
int get _lockedCount {
|
|
final explicit = drama.episodes.where((episode) => episode.locked).length;
|
|
if (explicit > 0) return explicit;
|
|
final inferred = drama.episodeCount - drama.freeEpisodes;
|
|
return inferred > 0 ? inferred : 0;
|
|
}
|
|
|
|
Widget _tagBadge(bool free) {
|
|
return Container(
|
|
key: Key('drama-tag-${drama.id}'),
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.badgePink,
|
|
borderRadius: BorderRadius.circular(AppDimens.pillRadius),
|
|
),
|
|
child: Text(
|
|
free ? l10n.free : l10n.originalTag,
|
|
style: const TextStyle(
|
|
color: AppColors.badgePinkText,
|
|
fontSize: AppDimens.cardMeta,
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _lockedBadge() {
|
|
return Container(
|
|
key: Key('drama-locked-${drama.id}'),
|
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.overlayDark,
|
|
borderRadius: BorderRadius.circular(AppDimens.pillRadius),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(Icons.lock_rounded, color: AppColors.onPrimary, size: 11),
|
|
const SizedBox(width: 2),
|
|
Text(
|
|
l10n.lockedEpisodeCount(_lockedCount),
|
|
style: const TextStyle(
|
|
color: AppColors.onPrimary,
|
|
fontSize: 9,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _episodeBadge() {
|
|
return Container(
|
|
key: Key('drama-episodes-badge-${drama.id}'),
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.badgeBeige,
|
|
borderRadius: BorderRadius.circular(AppDimens.pillRadius),
|
|
),
|
|
child: Text(
|
|
l10n.allEpisodesBadge(drama.episodeCount),
|
|
style: const TextStyle(
|
|
color: AppColors.onSurface,
|
|
fontSize: 9,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _title() {
|
|
return Text(
|
|
drama.title,
|
|
key: Key('home-drama-title-${drama.id}'),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
color: AppColors.onSurface,
|
|
fontSize: AppDimens.cardTitle,
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _genre() {
|
|
final genre = drama.genre.isEmpty ? drama.category : drama.genre;
|
|
return Text(
|
|
genre.isEmpty ? l10n.videoPending : genre,
|
|
key: Key('home-drama-genre-${drama.id}'),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
color: AppColors.muted,
|
|
fontSize: AppDimens.cardMeta,
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _footer() {
|
|
return Row(
|
|
children: [
|
|
Expanded(child: _genre()),
|
|
Container(
|
|
key: Key('drama-add-${drama.id}'),
|
|
width: _addSize,
|
|
height: _addSize,
|
|
decoration: const BoxDecoration(
|
|
color: AppColors.blue,
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: const Icon(
|
|
Icons.add_rounded,
|
|
color: AppColors.onPrimary,
|
|
size: _addIconSize,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _DiscoverCoverImage extends StatelessWidget {
|
|
const _DiscoverCoverImage({required this.path});
|
|
|
|
final String path;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final url = AppConfig.mediaUrl(path);
|
|
if (url.isEmpty) return _placeholder();
|
|
return Image.network(
|
|
url,
|
|
width: double.infinity,
|
|
fit: BoxFit.fitWidth,
|
|
loadingBuilder: (context, child, progress) {
|
|
if (progress == null) return child;
|
|
return _placeholder();
|
|
},
|
|
errorBuilder: (_, _, _) => _placeholder(),
|
|
);
|
|
}
|
|
|
|
Widget _placeholder() {
|
|
return AspectRatio(
|
|
aspectRatio: 3 / 4,
|
|
child: ColoredBox(
|
|
color: AppColors.card,
|
|
child: const Center(
|
|
child: Icon(
|
|
Icons.image_not_supported_outlined,
|
|
color: AppColors.muted,
|
|
size: 32,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|