feat(flutter): 重构四 Tab 与浏览页
This commit is contained in:
1 parent
99c72e2c32
commit
959edc0a32
41 files changed
+2148
-1179
No files matched your search
@@ -0,0 +1,70 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../../core/data/models/watch_progress.dart';
|
||||
import '../../core/data/repositories/watch_history_repository.dart';
|
||||
|
||||
/// Home browse channel, backed only by data already present in the catalogue.
|
||||
enum HomeChannel { hot, free, newReleases, ranking }
|
||||
|
||||
/// Local UI state for the browse-first home page.
|
||||
class HomeBrowseLogic extends ChangeNotifier {
|
||||
HomeBrowseLogic({required this.history}) {
|
||||
unawaited(refreshRecent());
|
||||
}
|
||||
|
||||
static const int recentLimit = 20;
|
||||
|
||||
final WatchHistoryRepository history;
|
||||
HomeChannel channel = HomeChannel.hot;
|
||||
List<WatchProgress> recent = const [];
|
||||
bool loadingRecent = false;
|
||||
bool _disposed = false;
|
||||
|
||||
/// First unfinished record with a real position.
|
||||
WatchProgress? get primaryRecord {
|
||||
for (final record in recent) {
|
||||
if (!record.finished && record.hasPosition) return record;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Changes the selected browse channel without triggering network work.
|
||||
void selectChannel(HomeChannel value) {
|
||||
if (channel == value) return;
|
||||
channel = value;
|
||||
_notify();
|
||||
}
|
||||
|
||||
/// Reloads continuation data; signed-out reads simply return an empty list.
|
||||
Future<void> refreshRecent() async {
|
||||
loadingRecent = true;
|
||||
_notify();
|
||||
try {
|
||||
recent = await history.recent(limit: recentLimit);
|
||||
} catch (_) {
|
||||
recent = const [];
|
||||
} finally {
|
||||
loadingRecent = false;
|
||||
_notify();
|
||||
}
|
||||
}
|
||||
|
||||
/// Refreshes continuation data when the home tab becomes visible again.
|
||||
void syncPage({required bool active, required bool wasActive}) {
|
||||
if (active && !wasActive) unawaited(refreshRecent());
|
||||
}
|
||||
|
||||
void _notify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,333 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/models/home_feed.dart';
|
||||
import '../../core/data/models/watch_progress.dart';
|
||||
import '../../core/data/repositories/watch_history_repository.dart';
|
||||
import '../../core/data/services/catalog_controller.dart';
|
||||
import '../../core/data/services/category_controller.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../core/theme/app_dimens.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../discover/widgets/drama_grid.dart';
|
||||
import '../discover/widgets/feed_banner_carousel.dart';
|
||||
import 'home_browse_logic.dart';
|
||||
import 'widgets/home_browse_header.dart';
|
||||
import 'widgets/home_continue_watching.dart';
|
||||
|
||||
/// Browse-first home page with channels, hero, continuation, and catalogue.
|
||||
class HomeBrowseView extends StatefulWidget {
|
||||
const HomeBrowseView({
|
||||
super.key,
|
||||
required this.active,
|
||||
required this.onSearch,
|
||||
required this.onProfile,
|
||||
required this.onTheater,
|
||||
required this.onHistory,
|
||||
required this.onOpenDrama,
|
||||
required this.onOpenContinue,
|
||||
});
|
||||
|
||||
final bool active;
|
||||
final VoidCallback onSearch;
|
||||
final VoidCallback onProfile;
|
||||
final VoidCallback onTheater;
|
||||
final VoidCallback onHistory;
|
||||
final Future<void> Function(Drama drama) onOpenDrama;
|
||||
final Future<void> Function(Drama drama, WatchProgress record) onOpenContinue;
|
||||
|
||||
@override
|
||||
State<HomeBrowseView> createState() => _HomeBrowseViewState();
|
||||
}
|
||||
|
||||
class _HomeBrowseViewState extends State<HomeBrowseView> {
|
||||
late final HomeBrowseLogic logic;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
logic = HomeBrowseLogic(history: context.read<WatchHistoryRepository>());
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant HomeBrowseView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
logic.syncPage(active: widget.active, wasActive: oldWidget.active);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
logic.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListenableBuilder(
|
||||
listenable: logic,
|
||||
builder: (context, _) => _page(context),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _page(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final categories = context.watch<CategoryController>();
|
||||
final catalog = context.watch<CatalogController>();
|
||||
final source = categories.feed.dramas.isEmpty
|
||||
? catalog.dramas
|
||||
: categories.feed.dramas;
|
||||
return SafeArea(
|
||||
bottom: false,
|
||||
child: Column(
|
||||
children: [
|
||||
HomeBrowseHeader(
|
||||
onSearch: widget.onSearch,
|
||||
onProfile: widget.onProfile,
|
||||
),
|
||||
Expanded(child: _body(l10n, categories, catalog, source)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(
|
||||
AppLocalizations l10n,
|
||||
CategoryController categories,
|
||||
CatalogController catalog,
|
||||
List<Drama> source,
|
||||
) {
|
||||
return RefreshIndicator(
|
||||
key: const Key('home-refresh'),
|
||||
color: AppColors.blue,
|
||||
backgroundColor: AppColors.card,
|
||||
onRefresh: () async {
|
||||
await Future.wait([categories.load(), logic.refreshRecent()]);
|
||||
},
|
||||
child: ListView(
|
||||
key: const Key('home-browse-page'),
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.only(bottom: AppDimens.spaceXl),
|
||||
children: _sections(l10n, catalog, source),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _sections(
|
||||
AppLocalizations l10n,
|
||||
CatalogController catalog,
|
||||
List<Drama> source,
|
||||
) {
|
||||
final dramas = _channelDramas(source, logic.channel);
|
||||
final continueItems = _continueItems(logic.recent, catalog.dramas);
|
||||
return [
|
||||
_channels(l10n),
|
||||
if (catalog.banners.isNotEmpty) _hero(catalog.banners, source),
|
||||
if (continueItems.isNotEmpty) ...[
|
||||
_continueHeader(l10n),
|
||||
HomeContinueWatching(
|
||||
items: continueItems,
|
||||
onPlay: (drama, record) =>
|
||||
unawaited(widget.onOpenContinue(drama, record)),
|
||||
),
|
||||
],
|
||||
_channelHeader(l10n),
|
||||
if (dramas.isEmpty)
|
||||
_empty()
|
||||
else
|
||||
DramaGrid(
|
||||
l10n: l10n,
|
||||
dramas: dramas,
|
||||
onOpen: (drama) => unawaited(widget.onOpenDrama(drama)),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Widget _continueHeader(AppLocalizations l10n) => _sectionHeader(
|
||||
l10n.continueWatching,
|
||||
actionKey: const Key('home-continue-all'),
|
||||
actionLabel: l10n.seeAll,
|
||||
onAction: widget.onHistory,
|
||||
);
|
||||
|
||||
Widget _channelHeader(AppLocalizations l10n) => _sectionHeader(
|
||||
_channelTitle(l10n),
|
||||
actionKey: const Key('home-popular-more'),
|
||||
actionLabel: l10n.seeAll,
|
||||
onAction: widget.onTheater,
|
||||
);
|
||||
|
||||
Widget _empty() => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppDimens.spaceXl),
|
||||
child: EmptyState(
|
||||
key: const Key('home-browse-empty'),
|
||||
icon: Icons.movie_filter_outlined,
|
||||
title: AppLocalizations.of(context)!.noStories,
|
||||
subtitle: AppLocalizations.of(context)!.emptyHint,
|
||||
compact: true,
|
||||
),
|
||||
);
|
||||
|
||||
Widget _channels(AppLocalizations l10n) {
|
||||
final entries = [
|
||||
(HomeChannel.hot, l10n.hot),
|
||||
(HomeChannel.free, l10n.free),
|
||||
(HomeChannel.newReleases, l10n.newDramas),
|
||||
(HomeChannel.ranking, l10n.rankingTab),
|
||||
];
|
||||
return SizedBox(
|
||||
height: AppDimens.buttonMedium,
|
||||
child: ListView.separated(
|
||||
key: const Key('home-channels'),
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimens.pageHorizontal,
|
||||
),
|
||||
itemCount: entries.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(width: AppDimens.spaceSm),
|
||||
itemBuilder: (context, index) {
|
||||
final entry = entries[index];
|
||||
final selected = logic.channel == entry.$1;
|
||||
return ChoiceChip(
|
||||
key: Key('home-channel-${entry.$1.name}'),
|
||||
label: Text(entry.$2),
|
||||
selected: selected,
|
||||
showCheckmark: false,
|
||||
onSelected: (_) => logic.selectChannel(entry.$1),
|
||||
backgroundColor: AppColors.card,
|
||||
selectedColor: AppColors.blue,
|
||||
side: BorderSide(
|
||||
color: selected ? AppColors.blue : AppColors.border,
|
||||
),
|
||||
labelStyle: TextStyle(
|
||||
color: selected ? AppColors.onPrimary : AppColors.muted,
|
||||
fontSize: AppDimens.chipFont,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppDimens.spaceMd),
|
||||
shape: const StadiumBorder(),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _hero(List<FeedBanner> banners, List<Drama> dramas) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: AppDimens.spaceMd),
|
||||
child: FeedBannerCarousel(
|
||||
key: const Key('home-hero-banner'),
|
||||
banners: banners,
|
||||
active: widget.active,
|
||||
dramaFor: (banner) => _dramaForBanner(banner, dramas),
|
||||
onOpen: (banner) {
|
||||
final drama = _dramaForBanner(banner, dramas);
|
||||
if (drama != null) unawaited(widget.onOpenDrama(drama));
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _sectionHeader(
|
||||
String title, {
|
||||
required Key actionKey,
|
||||
required String actionLabel,
|
||||
required VoidCallback onAction,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
AppDimens.pageHorizontal,
|
||||
AppDimens.spaceLg,
|
||||
AppDimens.spaceSm,
|
||||
AppDimens.spaceSm,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'Outfit',
|
||||
color: AppColors.onSurface,
|
||||
fontSize: AppDimens.sectionTitle,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
key: actionKey,
|
||||
onPressed: onAction,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.accent,
|
||||
minimumSize: const Size(AppDimens.tapTarget, AppDimens.tapTarget),
|
||||
),
|
||||
child: Text(actionLabel),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _channelTitle(AppLocalizations l10n) {
|
||||
return switch (logic.channel) {
|
||||
HomeChannel.hot => l10n.trendingMicroDramas,
|
||||
HomeChannel.free => l10n.free,
|
||||
HomeChannel.newReleases => l10n.newDramas,
|
||||
HomeChannel.ranking => l10n.rankingTitle,
|
||||
};
|
||||
}
|
||||
|
||||
List<Drama> _channelDramas(List<Drama> source, HomeChannel channel) {
|
||||
final dramas = List<Drama>.of(source);
|
||||
switch (channel) {
|
||||
case HomeChannel.hot:
|
||||
dramas.sort((a, b) {
|
||||
final hot = (b.isHot ? 1 : 0).compareTo(a.isHot ? 1 : 0);
|
||||
return hot != 0 ? hot : b.viewCount.compareTo(a.viewCount);
|
||||
});
|
||||
case HomeChannel.free:
|
||||
return dramas.where(_isFree).toList();
|
||||
case HomeChannel.newReleases:
|
||||
return dramas;
|
||||
case HomeChannel.ranking:
|
||||
dramas.sort((a, b) => b.viewCount.compareTo(a.viewCount));
|
||||
}
|
||||
return dramas;
|
||||
}
|
||||
|
||||
bool _isFree(Drama drama) {
|
||||
return drama.freeEpisodes > 0 ||
|
||||
drama.episodes.any((episode) => episode.isFree);
|
||||
}
|
||||
|
||||
Drama? _dramaForBanner(FeedBanner banner, List<Drama> dramas) {
|
||||
final id = banner.dramaId;
|
||||
if (id == null) return null;
|
||||
for (final drama in dramas) {
|
||||
if (drama.id == id) return drama;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
List<HomeContinueItem> _continueItems(
|
||||
List<WatchProgress> records,
|
||||
List<Drama> dramas,
|
||||
) {
|
||||
final items = <HomeContinueItem>[];
|
||||
for (final record in records) {
|
||||
if (record.finished || !record.hasPosition) continue;
|
||||
for (final drama in dramas) {
|
||||
if (drama.id == record.dramaId) {
|
||||
items.add((drama: drama, record: record));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,11 @@ class HomeLogic extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> playDrama(BuildContext context, Drama drama) async {
|
||||
Future<void> playDrama(
|
||||
BuildContext context,
|
||||
Drama drama, {
|
||||
String? episodeId,
|
||||
}) async {
|
||||
// 列表卡片只有一集预览,进入播放前补齐完整剧集,否则选集列表是空的。
|
||||
var playable = drama;
|
||||
try {
|
||||
@@ -78,11 +82,14 @@ class HomeLogic extends ChangeNotifier {
|
||||
// 取详情失败就用卡片自带的那一集起播。
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context).push(
|
||||
final index = episodeId == null
|
||||
? 0
|
||||
: playable.episodes.indexWhere((episode) => episode.id == episodeId);
|
||||
await Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => PlayerPage(
|
||||
drama: playable,
|
||||
initialIndex: 0,
|
||||
initialIndex: index < 0 ? 0 : index,
|
||||
wallet: context.read<WalletController>(),
|
||||
downloads: context.read<DownloadController>(),
|
||||
),
|
||||
@@ -90,14 +97,16 @@ class HomeLogic extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
void openProfile() => select(2);
|
||||
void openProfile() => select(3);
|
||||
|
||||
void discoverAction(DiscoverPageAction action) {
|
||||
switch (action) {
|
||||
case DiscoverPageAction.home:
|
||||
select(0);
|
||||
case DiscoverPageAction.my:
|
||||
case DiscoverPageAction.create:
|
||||
select(2);
|
||||
case DiscoverPageAction.my:
|
||||
select(3);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,6 +128,8 @@ class HomeLogic extends ChangeNotifier {
|
||||
select(0);
|
||||
case MyPageAction.discover:
|
||||
select(1, search: true);
|
||||
case MyPageAction.create:
|
||||
select(2);
|
||||
case MyPageAction.resume:
|
||||
select(0, resume: true);
|
||||
}
|
||||
@@ -128,8 +139,8 @@ class HomeLogic extends ChangeNotifier {
|
||||
if (videoImmersive) {
|
||||
backRequest++;
|
||||
notify();
|
||||
} else if (tab != 1) {
|
||||
select(1);
|
||||
} else if (tab != 0) {
|
||||
select(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ import 'package:provider/provider.dart';
|
||||
|
||||
import '../../core/data/models/drama.dart';
|
||||
import '../../core/data/services/catalog_controller.dart';
|
||||
import '../../core/data/services/download_controller.dart';
|
||||
import '../../core/data/services/wallet_controller.dart';
|
||||
import '../../core/platform/haptics.dart';
|
||||
import '../../core/theme/app_colors.dart';
|
||||
import '../../core/theme/app_theme.dart';
|
||||
@@ -17,13 +15,13 @@ import '../../core/widgets/empty_state.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../discover/discover_types.dart';
|
||||
import '../discover/discover_view.dart';
|
||||
import '../create/create_view.dart';
|
||||
import '../mine/mine_types.dart';
|
||||
import '../splash/splash_page.dart';
|
||||
import '../mine/mine_view.dart';
|
||||
import '../player/player_view.dart';
|
||||
import 'home_binding.dart';
|
||||
import 'home_browse_view.dart';
|
||||
import 'home_logic.dart';
|
||||
import 'widgets/home_menu_sheet.dart';
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
const HomePage({super.key});
|
||||
@@ -95,7 +93,7 @@ class HomeFailureView extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// The three primary destinations share a single route and keep their state.
|
||||
/// The four primary destinations share a single route and keep their state.
|
||||
class _HomeTabs extends StatefulWidget {
|
||||
const _HomeTabs({super.key, required this.dramas});
|
||||
|
||||
@@ -134,11 +132,7 @@ class _HomeTabsState extends State<_HomeTabs> {
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (didPop) return;
|
||||
if (!logic.videoImmersive && logic.tab == 1) {
|
||||
unawaited(_openMenu(context));
|
||||
} else {
|
||||
logic.onSystemBack();
|
||||
}
|
||||
logic.onSystemBack();
|
||||
},
|
||||
child: Scaffold(
|
||||
key: logic.scaffoldKey,
|
||||
@@ -152,28 +146,25 @@ class _HomeTabsState extends State<_HomeTabs> {
|
||||
Widget _body(BuildContext context) {
|
||||
return IndexedStack(
|
||||
index: logic.tab,
|
||||
children: [_player(context), _discover(context), _my(context)],
|
||||
children: [
|
||||
_home(context),
|
||||
_discover(context),
|
||||
const CreatePage(),
|
||||
_my(context),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _player(BuildContext context) {
|
||||
return PlayerPage(
|
||||
drama: widget.dramas.first,
|
||||
feedDramas: widget.dramas,
|
||||
onDramaChanged: logic.onDramaChanged,
|
||||
initialIndex: 0,
|
||||
homeMode: true,
|
||||
embedded: true,
|
||||
active: logic.tab == 0 && !logic.drawerOpen && !logic.detailOpen,
|
||||
resumeRequest: logic.resumeRequest,
|
||||
backRequest: logic.backRequest,
|
||||
onDiscover: () => logic.select(1),
|
||||
onMy: logic.openProfile,
|
||||
Widget _home(BuildContext context) {
|
||||
return HomeBrowseView(
|
||||
active: logic.tab == 0,
|
||||
onSearch: () => logic.select(1, search: true),
|
||||
onMenu: () => _openMenu(context),
|
||||
onImmersiveChanged: logic.onImmersiveChanged,
|
||||
wallet: context.read<WalletController>(),
|
||||
downloads: context.read<DownloadController>(),
|
||||
onProfile: logic.openProfile,
|
||||
onTheater: () => logic.select(1),
|
||||
onHistory: () => logic.openHistory(context),
|
||||
onOpenDrama: (drama) => logic.playDrama(context, drama),
|
||||
onOpenContinue: (drama, record) =>
|
||||
logic.playDrama(context, drama, episodeId: record.episodeId),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -191,7 +182,7 @@ class _HomeTabsState extends State<_HomeTabs> {
|
||||
|
||||
Widget _my(BuildContext context) {
|
||||
return MyPage(
|
||||
active: logic.tab == 2,
|
||||
active: logic.tab == 3,
|
||||
callbacks: MyPageCallbacks(
|
||||
onAction: logic.myAction,
|
||||
onDramaSelected: (drama) => logic.openDrama(context, drama),
|
||||
@@ -206,6 +197,7 @@ class _HomeTabsState extends State<_HomeTabs> {
|
||||
_navItem(context, l10n, 0),
|
||||
_navItem(context, l10n, 1),
|
||||
_navItem(context, l10n, 2),
|
||||
_navItem(context, l10n, 3),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -219,24 +211,32 @@ class _HomeTabsState extends State<_HomeTabs> {
|
||||
return switch (index) {
|
||||
0 => AppBottomNavItem(
|
||||
tabKey: const Key('tab-home'),
|
||||
icon: Icons.play_circle_outline_rounded,
|
||||
selectedIcon: Icons.play_circle_fill_rounded,
|
||||
icon: Icons.home_outlined,
|
||||
selectedIcon: Icons.home_rounded,
|
||||
label: l10n.homeTab,
|
||||
selected: selected,
|
||||
onTap: () => _selectTab(context, index),
|
||||
),
|
||||
1 => AppBottomNavItem(
|
||||
tabKey: const Key('tab-discover'),
|
||||
tabKey: const Key('tab-theater'),
|
||||
icon: Icons.explore_outlined,
|
||||
selectedIcon: Icons.explore_rounded,
|
||||
label: l10n.discoverTab,
|
||||
label: l10n.theaterTab,
|
||||
selected: selected,
|
||||
onTap: () => _selectTab(context, index),
|
||||
),
|
||||
2 => AppBottomNavItem(
|
||||
tabKey: const Key('tab-create'),
|
||||
icon: Icons.add_box_outlined,
|
||||
selectedIcon: Icons.add_box_rounded,
|
||||
label: l10n.createTab,
|
||||
selected: selected,
|
||||
onTap: () => _selectTab(context, index),
|
||||
),
|
||||
_ => AppBottomNavItem(
|
||||
tabKey: const Key('tab-my'),
|
||||
icon: Icons.video_library_outlined,
|
||||
selectedIcon: Icons.video_library_rounded,
|
||||
tabKey: const Key('tab-mine'),
|
||||
icon: Icons.person_outline_rounded,
|
||||
selectedIcon: Icons.person_rounded,
|
||||
label: l10n.myTab,
|
||||
selected: selected,
|
||||
onTap: () => _selectTab(context, index),
|
||||
@@ -251,22 +251,4 @@ class _HomeTabsState extends State<_HomeTabs> {
|
||||
}
|
||||
logic.select(tab);
|
||||
}
|
||||
|
||||
Future<void> _openMenu(BuildContext context) async {
|
||||
logic.setMenuOpen(true);
|
||||
await showModalBottomSheet<void>(
|
||||
context: context,
|
||||
backgroundColor: AppColors.card,
|
||||
showDragHandle: true,
|
||||
isScrollControlled: true,
|
||||
builder: (_) => HomeMenuSheet(
|
||||
drama: logic.currentDrama,
|
||||
onOpenSeries: () => logic.openCurrentSeries(context),
|
||||
onDiscover: () => logic.select(1),
|
||||
onHistory: () => logic.openHistory(context),
|
||||
onWatchlist: () => logic.openFavorites(context),
|
||||
),
|
||||
);
|
||||
logic.setMenuOpen(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
const double _searchHeight = 36;
|
||||
|
||||
/// Fixed home header with catalogue search, weekday, and profile entry.
|
||||
class HomeBrowseHeader extends StatelessWidget {
|
||||
const HomeBrowseHeader({
|
||||
super.key,
|
||||
required this.onSearch,
|
||||
required this.onProfile,
|
||||
});
|
||||
|
||||
final VoidCallback onSearch;
|
||||
final VoidCallback onProfile;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final weekday = _weekday(l10n);
|
||||
return SizedBox(
|
||||
height: AppDimens.contentHeaderHeight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimens.pageHorizontal,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(child: _search(l10n, onSearch)),
|
||||
const SizedBox(width: AppDimens.spaceSm),
|
||||
_weekdayText(weekday),
|
||||
const SizedBox(width: AppDimens.spaceSm),
|
||||
_profile(l10n),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _weekday(AppLocalizations l10n) {
|
||||
return switch (DateTime.now().weekday) {
|
||||
DateTime.monday => l10n.weekdayMon,
|
||||
DateTime.tuesday => l10n.weekdayTue,
|
||||
DateTime.wednesday => l10n.weekdayWed,
|
||||
DateTime.thursday => l10n.weekdayThu,
|
||||
DateTime.friday => l10n.weekdayFri,
|
||||
DateTime.saturday => l10n.weekdaySat,
|
||||
_ => l10n.weekdaySun,
|
||||
};
|
||||
}
|
||||
|
||||
Widget _search(AppLocalizations l10n, VoidCallback onTap) {
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: l10n.search,
|
||||
child: InkWell(
|
||||
key: const Key('home-search'),
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppDimens.pillRadius),
|
||||
child: Container(
|
||||
height: _searchHeight,
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppDimens.spaceMd),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.input,
|
||||
borderRadius: BorderRadius.circular(AppDimens.pillRadius),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.search_rounded,
|
||||
color: AppColors.subtle,
|
||||
size: 17,
|
||||
),
|
||||
const SizedBox(width: AppDimens.spaceSm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.searchDiscover,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.subtle,
|
||||
fontSize: AppDimens.caption,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _weekdayText(String value) {
|
||||
return Text(
|
||||
value,
|
||||
key: const Key('home-weekday'),
|
||||
style: const TextStyle(
|
||||
color: AppColors.muted,
|
||||
fontSize: AppDimens.caption,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _profile(AppLocalizations l10n) {
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: l10n.myTab,
|
||||
child: InkWell(
|
||||
key: const Key('home-profile'),
|
||||
customBorder: const CircleBorder(),
|
||||
onTap: onProfile,
|
||||
child: Container(
|
||||
width: AppDimens.tapTarget,
|
||||
height: AppDimens.tapTarget,
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.card,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.person_rounded,
|
||||
color: AppColors.onSurface,
|
||||
size: AppDimens.accountIcon,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/data/models/drama.dart';
|
||||
import '../../../core/data/models/watch_progress.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/widgets/remote_image.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
const double _railHeight = 96;
|
||||
const double _cardWidth = 286;
|
||||
const double _coverWidth = 64;
|
||||
const double _playSize = 34;
|
||||
|
||||
/// One drama/record pair rendered by the continuation rail.
|
||||
typedef HomeContinueItem = ({Drama drama, WatchProgress record});
|
||||
|
||||
/// Home continuation cards for records that still have unwatched time.
|
||||
class HomeContinueWatching extends StatelessWidget {
|
||||
const HomeContinueWatching({
|
||||
super.key,
|
||||
required this.items,
|
||||
required this.onPlay,
|
||||
});
|
||||
|
||||
final List<HomeContinueItem> items;
|
||||
final void Function(Drama drama, WatchProgress record) onPlay;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (items.isEmpty) return const SizedBox.shrink();
|
||||
return SizedBox(
|
||||
key: const Key('home-continue-watching'),
|
||||
height: _railHeight,
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimens.pageHorizontal,
|
||||
),
|
||||
itemCount: items.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(width: AppDimens.spaceSm),
|
||||
itemBuilder: (context, index) {
|
||||
final item = items[index];
|
||||
return _ContinueCard(
|
||||
item: item,
|
||||
onPlay: () => onPlay(item.drama, item.record),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ContinueCard extends StatelessWidget {
|
||||
const _ContinueCard({required this.item, required this.onPlay});
|
||||
|
||||
final HomeContinueItem item;
|
||||
final VoidCallback onPlay;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
return Container(
|
||||
width: _cardWidth,
|
||||
padding: const EdgeInsets.all(AppDimens.spaceSm),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.card,
|
||||
borderRadius: BorderRadius.circular(AppDimens.cardRadius),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(AppDimens.innerRadius),
|
||||
child: RemoteImage(
|
||||
item.drama.posterUrl,
|
||||
width: _coverWidth,
|
||||
height: _railHeight - AppDimens.spaceLg,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimens.spaceSm),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.drama.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.onSurface,
|
||||
fontSize: AppDimens.previewCardTitle,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimens.spaceXs),
|
||||
Text(
|
||||
_progressText(l10n, item.drama, item.record),
|
||||
key: Key('home-continue-progress-${item.drama.id}'),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.muted,
|
||||
fontSize: AppDimens.cardMeta,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimens.spaceSm),
|
||||
IconButton(
|
||||
key: Key('home-continue-play-${item.drama.id}'),
|
||||
onPressed: onPlay,
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: AppColors.blue,
|
||||
foregroundColor: AppColors.onPrimary,
|
||||
fixedSize: const Size.square(_playSize),
|
||||
padding: EdgeInsets.zero,
|
||||
),
|
||||
icon: const Icon(
|
||||
Icons.play_arrow_rounded,
|
||||
size: AppDimens.accountIcon,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _progressText(
|
||||
AppLocalizations l10n,
|
||||
Drama drama,
|
||||
WatchProgress record,
|
||||
) {
|
||||
final episode = drama.episodes.where(
|
||||
(value) => value.id == record.episodeId,
|
||||
);
|
||||
final number = episode.isEmpty ? 1 : episode.first.number;
|
||||
final remaining = record.duration - record.position;
|
||||
final minutes = remaining.inSeconds <= 0
|
||||
? 0
|
||||
: (remaining.inSeconds / Duration.secondsPerMinute).ceil();
|
||||
return l10n.episodeRemaining(number, minutes);
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ class HomeMenuSheet extends StatelessWidget {
|
||||
_item(
|
||||
key: const Key('drawer-discover'),
|
||||
icon: Icons.explore_outlined,
|
||||
label: l10n.discoverTab,
|
||||
label: l10n.theaterTab,
|
||||
onTap: () => closeThen(onDiscover),
|
||||
),
|
||||
_item(
|
||||
|
||||
Reference in new issue
Block a user