fix(discover): 固定发现页顶栏

This commit is contained in:
Zhou Weidong committed 2026-10-19 17:54:44 +08:00
1 parent 1eaab2a150
commit 16175803ed
2 files changed
+63 -3

No files matched your search

+6 -3
View File
@@ -113,6 +113,7 @@ class _DiscoverPageState extends State<DiscoverPage> {
bottom: !widget.embedded,
child: Column(
children: [
_header(l10n),
Expanded(child: _feed(l10n, categories, allDramas, visible)),
if (!widget.embedded) _bottomNav(l10n),
],
@@ -137,7 +138,6 @@ class _DiscoverPageState extends State<DiscoverPage> {
) => CustomScrollView(
controller: logic.scroll,
slivers: [
SliverToBoxAdapter(child: _header(l10n)),
SliverToBoxAdapter(child: _search()),
SliverToBoxAdapter(
child: Padding(
@@ -222,8 +222,10 @@ class _DiscoverPageState extends State<DiscoverPage> {
);
Widget _header(AppLocalizations l10n) {
return Padding(
padding: const EdgeInsets.fromLTRB(14, 2, 14, 10),
return SizedBox(
height: 46,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 14),
child: Row(
children: [
Container(
@@ -286,6 +288,7 @@ class _DiscoverPageState extends State<DiscoverPage> {
),
],
),
),
);
}
@@ -132,6 +132,43 @@ void main() {
);
});
testWidgets('should_keep_discover_header_fixed_when_content_scrolls', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await _pumpApp(
tester,
categoryRepository: _GridCategoryRepository(
discoverFeed: _tallDiscoverFeed,
),
);
await tester.tap(find.byKey(const Key('tab-discover')));
await tester.pumpAndSettle();
final headerBefore = tester.getTopLeft(
find.byKey(const Key('discover-search-button')),
);
final contentBefore = tester.getTopLeft(
find.byKey(const Key('home-category-chips')),
);
await tester.drag(find.byType(CustomScrollView), const Offset(0, -40));
await tester.pumpAndSettle();
expect(
tester.getTopLeft(find.byKey(const Key('discover-search-button'))),
headerBefore,
);
expect(
tester.getTopLeft(find.byKey(const Key('home-category-chips'))).dy,
lessThan(contentBefore.dy),
);
});
testWidgets('should_keep_empty_messages_when_feed_has_no_dramas', (
tester,
) async {
@@ -341,3 +378,23 @@ final _defaultDiscoverFeed = HomeFeed(
),
],
);
final _tallDiscoverFeed = HomeFeed(
sections: [
FeedSection(
code: 'hot',
title: 'Hot',
dramas: [
for (var index = 0; index < 12; index++)
Drama(
id: 'tall-$index',
title: 'Tall Drama $index',
synopsis: 'Tall Drama $index synopsis',
posterUrl: '/files/tall-$index.png',
genre: 'Urban Romance',
detailLoaded: true,
),
],
),
],
);