feat(flutter): 增加榜单新剧分页与预约刷新

This commit is contained in:
Zhou Weidong committed 2026-10-20 16:53:07 +08:00
1 parent 805762f761
commit c4dcb714ab
12 files changed
+611 -96

No files matched your search

+168 -46
View File
@@ -10,9 +10,12 @@ import '../../core/data/models/drama.dart';
import '../../core/data/services/catalog_controller.dart';
import '../../core/formatting/count_format.dart';
import '../../core/theme/app_colors.dart';
import '../../core/widgets/app_pull_to_refresh.dart';
import '../../core/widgets/paged_local_list.dart';
import '../../core/widgets/remote_image.dart';
import '../../core/widgets/subpage_header.dart';
import '../../l10n/app_localizations.dart';
import '../discover/widgets/drama_grid.dart';
import '../player/open_player.dart';
const int _moreLimit = 12;
@@ -21,18 +24,83 @@ const double _cardPadding = 8;
const double _cardWidth = 124;
const double _rowHeight = 204;
const double _cardRadius = 12;
const double _loadMoreThreshold = 200;
/// 新剧页:暖色首映厅,今日首映大卡 + 横向更多新剧。
class NewReleasesPage extends StatelessWidget {
class NewReleasesPage extends StatefulWidget {
const NewReleasesPage({super.key});
@override
State<NewReleasesPage> createState() => _NewReleasesPageState();
}
class _NewReleasesPageState extends State<NewReleasesPage> {
final ScrollController _scroll = ScrollController();
PagedLocalListController<Drama>? _pager;
bool _refreshing = false;
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (_pager != null) return;
_pager = PagedLocalListController<Drama>(
items: _newest(context.read<CatalogController>().dramas),
)..addListener(_rebuild);
}
@override
void dispose() {
_pager
?..removeListener(_rebuild)
..dispose();
_scroll.dispose();
super.dispose();
}
void _rebuild() {
if (mounted) setState(() {});
}
List<Drama> _newest(List<Drama> source) {
return [...source]..sort((a, b) => b.id.compareTo(a.id));
}
Future<void> _refresh() async {
if (_refreshing) return;
_refreshing = true;
try {
final catalog = context.read<CatalogController>();
await catalog.refresh();
if (!mounted) return;
_pager!.replaceAll(_newest(catalog.dramas));
if (_scroll.hasClients) {
_scroll.jumpTo(_scroll.position.minScrollExtent);
}
} finally {
_refreshing = false;
}
}
bool _onScroll(ScrollNotification notification) {
if (notification.depth != 0 || _refreshing) return false;
final reachedBottom =
notification.metrics.extentAfter <= _loadMoreThreshold;
if (reachedBottom &&
(notification is ScrollUpdateNotification ||
notification is ScrollEndNotification ||
notification is OverscrollNotification)) {
unawaited(_pager!.loadMore());
}
return false;
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final dramas = [...context.read<CatalogController>().dramas]
..sort((a, b) => b.id.compareTo(a.id));
final hero = dramas.isEmpty ? null : dramas.first;
final more = dramas.skip(1).take(_moreLimit).toList();
final pager = _pager!;
final visible = pager.visibleItems;
final hero = visible.isEmpty ? null : visible.first;
final more = pager.items.skip(1).take(_moreLimit).toList();
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.dark,
child: Scaffold(
@@ -54,54 +122,93 @@ class NewReleasesPage extends StatelessWidget {
title: l10n.newReleasesTitle,
subtitle: l10n.newReleasesSubtitle,
backKey: const Key('new-releases-back'),
actions: _countChip(l10n, dramas.length),
actions: _countChip(l10n, pager.items.length),
),
Expanded(
child: hero == null
? Center(
child: Text(
l10n.noStories,
key: const Key('new-releases-empty'),
style: const TextStyle(color: AppColors.muted),
),
)
: ListView(
padding: const EdgeInsets.only(bottom: 24),
children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
),
child: _heroCard(context, l10n, hero),
),
const SizedBox(height: 14),
const _FilmStrip(),
const SizedBox(height: 14),
if (more.isNotEmpty) ...[
_moreHeader(l10n),
const SizedBox(height: 10),
SizedBox(
height: _rowHeight,
child: ListView.separated(
key: const Key('new-releases-row'),
scrollDirection: Axis.horizontal,
child: NotificationListener<ScrollNotification>(
onNotification: _onScroll,
child: AppPullToRefresh(
key: const Key('new-releases-refresh'),
onRefresh: _refresh,
child: ListView(
key: const Key('new-releases-list'),
controller: _scroll,
physics: const AlwaysScrollableScrollPhysics(),
padding: const EdgeInsets.only(bottom: 24),
children: hero == null
? [
SizedBox(
height: 420,
child: Center(
child: Text(
l10n.noStories,
key: const Key('new-releases-empty'),
style: const TextStyle(
color: AppColors.muted,
),
),
),
),
]
: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
),
itemCount: more.length,
separatorBuilder: (_, _) =>
const SizedBox(width: 10),
itemBuilder: (context, index) => _moreCard(
context,
l10n,
more[index],
index,
child: _heroCard(context, l10n, hero),
),
const SizedBox(height: 14),
const _FilmStrip(),
const SizedBox(height: 14),
if (more.isNotEmpty) ...[
_moreHeader(l10n),
const SizedBox(height: 10),
SizedBox(
height: _rowHeight,
child: ListView.separated(
key: const Key('new-releases-row'),
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(
horizontal: 16,
),
itemCount: more.length,
separatorBuilder: (_, _) =>
const SizedBox(width: 10),
itemBuilder: (context, index) =>
_moreCard(
context,
l10n,
more[index],
index,
),
),
),
],
const SizedBox(height: 20),
_allHeader(l10n),
const SizedBox(height: 10),
DramaGrid(
key: const Key('new-releases-all-grid'),
l10n: l10n,
dramas: visible,
onOpen: (drama) => unawaited(
playDramaFromCatalog(context, drama),
),
),
),
],
],
),
PagedLoadFooter(
loading: pager.loading,
hasMore: pager.hasMore,
hasItems: pager.items.isNotEmpty,
loadMoreKey: const Key(
'new-releases-load-more',
),
noMoreKey: const Key('new-releases-no-more'),
noMoreLabel: l10n.noMore,
),
],
),
),
),
),
],
),
@@ -267,6 +374,21 @@ class NewReleasesPage extends StatelessWidget {
);
}
Widget _allHeader(AppLocalizations l10n) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
l10n.newReleasesAll,
key: const Key('new-releases-all-header'),
style: const TextStyle(
color: AppColors.onSurface,
fontSize: 16,
fontWeight: FontWeight.w800,
),
),
);
}
Widget _moreCard(
BuildContext context,
AppLocalizations l10n,