feat(flutter): 剧场页搜索与吸顶筛选精致化
This commit is contained in:
1 parent
f9d4f982f0
commit
5283ab2549
3 files changed
+204
-33
No files matched your search
@@ -31,6 +31,8 @@ const double _categoryTabHeight = 44;
|
||||
const double _categoryTabGap = 20;
|
||||
const double _categorySelectedFontSize = 16;
|
||||
const double _categoryFontSize = 15;
|
||||
const double _stickyHeaderHeight = 102;
|
||||
const Duration _stickyHeaderTransition = Duration(milliseconds: 200);
|
||||
|
||||
/// K28-A2 剧场页:搜索、分类/语言 chips 与双列剧库。
|
||||
class DiscoverPage extends StatefulWidget {
|
||||
@@ -53,6 +55,7 @@ class DiscoverPage extends StatefulWidget {
|
||||
|
||||
class _DiscoverPageState extends State<DiscoverPage> {
|
||||
late final DiscoverLogic logic;
|
||||
bool _headerScrolled = false;
|
||||
|
||||
bool get embedded => widget.callbacks.embedded;
|
||||
|
||||
@@ -60,9 +63,17 @@ class _DiscoverPageState extends State<DiscoverPage> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
logic = DiscoverBinding().create(search: context.read<SearchRepository>());
|
||||
logic.scroll.addListener(_onScroll);
|
||||
if (widget.focusSearch) _focusOnFirstFrame();
|
||||
}
|
||||
|
||||
void _onScroll() {
|
||||
final scrolled = logic.scroll.hasClients && logic.scroll.offset > 0;
|
||||
if (scrolled != _headerScrolled) {
|
||||
setState(() => _headerScrolled = scrolled);
|
||||
}
|
||||
}
|
||||
|
||||
void _focusOnFirstFrame() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted && widget.active) logic.openSearch();
|
||||
@@ -82,6 +93,7 @@ class _DiscoverPageState extends State<DiscoverPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
logic.scroll.removeListener(_onScroll);
|
||||
logic.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -124,20 +136,73 @@ class _DiscoverPageState extends State<DiscoverPage> {
|
||||
}
|
||||
|
||||
Widget _feed(AppLocalizations l10n, CategoryController categories) {
|
||||
final showHeader = _showStickyHeader(categories);
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onTap: logic.searchFocus.unfocus,
|
||||
child: RefreshIndicator(
|
||||
key: const Key('discover-refresh'),
|
||||
color: AppColors.blue,
|
||||
backgroundColor: AppColors.card,
|
||||
onRefresh: categories.load,
|
||||
child: ListView(
|
||||
controller: logic.scroll,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.only(bottom: AppDimens.spaceXl),
|
||||
children: _content(l10n, categories),
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned.fill(
|
||||
child: RefreshIndicator(
|
||||
key: const Key('discover-refresh'),
|
||||
color: AppColors.blue,
|
||||
backgroundColor: AppColors.card,
|
||||
strokeWidth: 2,
|
||||
edgeOffset: _stickyHeaderHeight + 8,
|
||||
onRefresh: categories.load,
|
||||
child: ListView(
|
||||
controller: logic.scroll,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: EdgeInsets.only(
|
||||
top: showHeader ? _stickyHeaderHeight : 0,
|
||||
bottom: AppDimens.spaceXl,
|
||||
),
|
||||
children: _content(l10n, categories),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (showHeader)
|
||||
Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: _stickyHeader(l10n, categories),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _showStickyHeader(CategoryController categories) {
|
||||
if (logic.hasSearchQuery || categories.error != null) return false;
|
||||
return !(categories.loading && categories.feed.sections.isEmpty);
|
||||
}
|
||||
|
||||
Widget _stickyHeader(AppLocalizations l10n, CategoryController categories) {
|
||||
return AnimatedContainer(
|
||||
key: const Key('theater-sticky-header'),
|
||||
duration: _stickyHeaderTransition,
|
||||
curve: Curves.easeOut,
|
||||
decoration: BoxDecoration(
|
||||
color: _headerScrolled ? AppColors.ink : Colors.transparent,
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: _headerScrolled ? AppColors.border : Colors.transparent,
|
||||
),
|
||||
),
|
||||
boxShadow: _headerScrolled
|
||||
? const [
|
||||
BoxShadow(
|
||||
color: Color(0x14000000),
|
||||
blurRadius: 8,
|
||||
offset: Offset(0, 2),
|
||||
),
|
||||
]
|
||||
: const [],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [_categoryTabs(l10n, categories), _toolbar(l10n, categories)],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -183,8 +248,6 @@ class _DiscoverPageState extends State<DiscoverPage> {
|
||||
? categories.feed.dramas
|
||||
: categories.dramasOf(logic.selectedCategoryId!);
|
||||
return [
|
||||
_categoryTabs(l10n, categories),
|
||||
_toolbar(l10n, categories),
|
||||
if (dramas.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 40),
|
||||
|
||||
Reference in new issue
Block a user