287 lines
9.2 KiB
Dart
287 lines
9.2 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../core/config/app_config.dart';
|
|
import '../../core/data/models/drama.dart';
|
|
import '../../core/data/services/auth_controller.dart';
|
|
import '../../core/data/services/catalog_controller.dart';
|
|
import '../../core/widgets/auth_gate.dart';
|
|
import '../../core/theme/app_colors.dart';
|
|
import '../../l10n/app_localizations.dart';
|
|
import '../discover/discover_view.dart';
|
|
import '../mine/mine_view.dart';
|
|
import '../player/player_view.dart';
|
|
import 'home_binding.dart';
|
|
import 'home_logic.dart';
|
|
import 'widgets/home_quick_drawer.dart';
|
|
|
|
class HomePage extends StatelessWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final catalog = context.watch<CatalogController>();
|
|
final l10n = AppLocalizations.of(context)!;
|
|
return Theme(
|
|
data: ThemeData.dark(useMaterial3: true),
|
|
child: _buildHome(context, catalog, l10n),
|
|
);
|
|
}
|
|
|
|
Widget _buildHome(
|
|
BuildContext context,
|
|
CatalogController catalog,
|
|
AppLocalizations l10n,
|
|
) {
|
|
if (catalog.loading) {
|
|
return const Scaffold(
|
|
backgroundColor: Colors.black,
|
|
body: Center(child: CircularProgressIndicator()),
|
|
);
|
|
}
|
|
if (catalog.error != null || catalog.dramas.isEmpty) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.black,
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Text(catalog.error == null ? l10n.noStories : l10n.catalogError),
|
|
const SizedBox(height: 12),
|
|
FilledButton(onPressed: catalog.load, child: Text(l10n.retry)),
|
|
if (kDebugMode) ...[
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
AppConfig.apiBaseUrl,
|
|
style: const TextStyle(fontSize: 12, color: Colors.white54),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
return _HomeTabs(
|
|
key: ValueKey(catalog.dramas.first.id),
|
|
dramas: catalog.dramas,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The three primary destinations share a single route and keep their state.
|
|
class _HomeTabs extends StatefulWidget {
|
|
const _HomeTabs({super.key, required this.dramas});
|
|
|
|
final List<Drama> dramas;
|
|
|
|
@override
|
|
State<_HomeTabs> createState() => _HomeTabsState();
|
|
}
|
|
|
|
class _HomeTabsState extends State<_HomeTabs> {
|
|
late final HomeLogic logic;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
logic = HomeBinding().create(widget.dramas);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
logic.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: logic,
|
|
builder: (context, _) => _scaffold(context),
|
|
);
|
|
}
|
|
|
|
Widget _scaffold(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context)!;
|
|
// 登录态统一从 AuthController 取(原来是 home_logic 里的本地演示开关)
|
|
final signedIn = context.watch<AuthController>().isSignedIn;
|
|
return PopScope(
|
|
canPop: false,
|
|
onPopInvokedWithResult: (didPop, _) {
|
|
if (didPop) return;
|
|
logic.onSystemBack();
|
|
},
|
|
child: Scaffold(
|
|
key: logic.scaffoldKey,
|
|
backgroundColor: const Color(0xFF0B0C10),
|
|
drawer: HomeQuickDrawer(
|
|
drama: logic.currentDrama,
|
|
onOpenSeries: () => logic.openCurrentSeries(context),
|
|
onDiscover: () => logic.selectFromMenu(1),
|
|
onHistory: () => logic.openLibrary(section: 0),
|
|
onWatchlist: logic.openLibrary,
|
|
onLiked: () => logic.selectFromMenu(2, mySection: 2),
|
|
),
|
|
drawerEnableOpenDragGesture: false,
|
|
onDrawerChanged: logic.onDrawerChanged,
|
|
body: IndexedStack(
|
|
index: logic.tab,
|
|
children: [
|
|
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,
|
|
onSearch: () => logic.select(1, search: true),
|
|
onMenu: logic.openMenu,
|
|
onImmersiveChanged: logic.onImmersiveChanged,
|
|
),
|
|
DiscoverPage(
|
|
drama: logic.currentDrama,
|
|
dramas: widget.dramas,
|
|
onDramaSelected: (drama) => logic.playDrama(context, drama),
|
|
duration: Duration.zero,
|
|
embedded: true,
|
|
active: logic.tab == 1,
|
|
searchRequest: logic.searchRequest,
|
|
signedIn: signedIn,
|
|
onSignIn: () => openAuthPage(context),
|
|
onCoins: logic.openProfile,
|
|
onRewards: logic.openProfile,
|
|
onAction: (action) => logic.discoverAction(context, action),
|
|
),
|
|
MyPage(
|
|
drama: logic.currentDrama,
|
|
dramas: widget.dramas,
|
|
onDramaSelected: (drama) => logic.openDrama(context, drama),
|
|
duration: Duration.zero,
|
|
initialSection: logic.mySection,
|
|
profile: logic.profile,
|
|
sectionRequest: logic.sectionRequest,
|
|
embedded: true,
|
|
active: logic.tab == 2,
|
|
onAction: logic.myAction,
|
|
signedIn: signedIn,
|
|
onSignIn: () => openAuthPage(context),
|
|
onSignOut: () => context.read<AuthController>().signOut(),
|
|
),
|
|
],
|
|
),
|
|
bottomNavigationBar: logic.videoImmersive
|
|
? null
|
|
: SafeArea(
|
|
top: false,
|
|
child: Container(
|
|
key: const Key('home-tabs-bar'),
|
|
height: 63,
|
|
decoration: const BoxDecoration(
|
|
color: Color(0xFF0D0D11),
|
|
border: Border(top: BorderSide(color: Color(0xFF242329))),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
_TabButton(
|
|
key: const Key('tab-discover'),
|
|
icon: Icons.home_outlined,
|
|
selectedIcon: Icons.home_rounded,
|
|
label: l10n.homeTab,
|
|
selected: logic.tab == 1,
|
|
onTap: () => logic.select(1),
|
|
),
|
|
_TabButton(
|
|
key: const Key('tab-home'),
|
|
icon: Icons.movie_outlined,
|
|
selectedIcon: Icons.movie_rounded,
|
|
label: l10n.shortsTab,
|
|
selected: logic.tab == 0,
|
|
onTap: () => logic.select(0),
|
|
),
|
|
_TabButton(
|
|
key: const Key('tab-my-list'),
|
|
icon: Icons.bookmark_border_rounded,
|
|
selectedIcon: Icons.bookmark_rounded,
|
|
label: l10n.myListTab,
|
|
selected: logic.tab == 2 && !logic.profile,
|
|
onTap: logic.openLibrary,
|
|
),
|
|
_TabButton(
|
|
key: const Key('tab-my'),
|
|
icon: Icons.person_outline_rounded,
|
|
selectedIcon: Icons.person_rounded,
|
|
label: l10n.myTab,
|
|
selected: logic.tab == 2 && logic.profile,
|
|
onTap: logic.openProfile,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _TabButton extends StatelessWidget {
|
|
const _TabButton({
|
|
super.key,
|
|
required this.icon,
|
|
required this.selectedIcon,
|
|
required this.label,
|
|
required this.selected,
|
|
required this.onTap,
|
|
});
|
|
final IconData icon;
|
|
final IconData selectedIcon;
|
|
final String label;
|
|
final bool selected;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Expanded(
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 3),
|
|
decoration: selected
|
|
? BoxDecoration(
|
|
color: AppColors.blue,
|
|
borderRadius: BorderRadius.circular(14),
|
|
)
|
|
: null,
|
|
child: Icon(
|
|
selected ? selectedIcon : icon,
|
|
size: 20,
|
|
color: selected ? Colors.white : AppColors.muted,
|
|
),
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
label,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: 10,
|
|
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
|
|
color: selected ? AppColors.blue : AppColors.muted,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|