244 lines
7.3 KiB
Dart
244 lines
7.3 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../core/data/models/drama.dart';
|
|
import '../../core/data/services/catalog_controller.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)),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
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)!;
|
|
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.selectFromMenu(2, mySection: 0),
|
|
onWatchlist: () => logic.selectFromMenu(2, mySection: 1),
|
|
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.select(2),
|
|
onSearch: () => logic.select(1, search: true),
|
|
onMenu: logic.openMenu,
|
|
onImmersiveChanged: logic.onImmersiveChanged,
|
|
),
|
|
DiscoverPage(
|
|
drama: logic.currentDrama,
|
|
dramas: widget.dramas,
|
|
onDramaSelected: (drama) => logic.openDrama(context, drama),
|
|
duration: Duration.zero,
|
|
embedded: true,
|
|
active: logic.tab == 1,
|
|
searchRequest: logic.searchRequest,
|
|
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,
|
|
sectionRequest: logic.sectionRequest,
|
|
embedded: true,
|
|
active: logic.tab == 2,
|
|
onAction: logic.myAction,
|
|
),
|
|
],
|
|
),
|
|
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(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
_TabButton(
|
|
key: const Key('tab-home'),
|
|
icon: Icons.play_circle_outline_rounded,
|
|
label: l10n.homeTab,
|
|
selected: logic.tab == 0,
|
|
onTap: () => logic.select(0),
|
|
),
|
|
_TabButton(
|
|
key: const Key('tab-discover'),
|
|
icon: Icons.explore_outlined,
|
|
label: l10n.discoverTab,
|
|
selected: logic.tab == 1,
|
|
onTap: () => logic.select(1),
|
|
),
|
|
_TabButton(
|
|
key: const Key('tab-my'),
|
|
icon: Icons.video_library_outlined,
|
|
label: l10n.myTab,
|
|
selected: logic.tab == 2,
|
|
onTap: () => logic.select(2),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _TabButton extends StatelessWidget {
|
|
const _TabButton({
|
|
super.key,
|
|
required this.icon,
|
|
required this.label,
|
|
required this.selected,
|
|
required this.onTap,
|
|
});
|
|
final IconData icon;
|
|
final String label;
|
|
final bool selected;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => InkWell(
|
|
onTap: onTap,
|
|
child: SizedBox(
|
|
width: 80,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
icon,
|
|
size: 21,
|
|
color: selected ? const Color(0xFFFF5C37) : const Color(0xFFE6E1DE),
|
|
),
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: 10,
|
|
color: selected
|
|
? const Color(0xFFFF5C37)
|
|
: const Color(0xFFE6E1DE),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|