SliverFloatingHeader (#151145)

A sliver that shows its [child] when the user scrolls forward and hides it when the user scrolls backwards. Similar headers can be found in  Google Photos and Facebook.

This sliver is preferable to the general purpose SliverPersistentHeader for its relatively narrow use case because there's no need to create a SliverPersistentHeaderDelegate or to predict the header's size.

https://github.com/flutter/flutter/assets/1377460/82b67dfb-5d38-4adf-9415-fc8527d0eb9f
This commit is contained in:
Hans Muller
2024-07-03 12:52:52 -07:00
committed by GitHub
parent f60f85abcd
commit d1e150099e
8 changed files with 700 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/sliver/sliver_floating_header.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('SliverFloatingHeader example', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverFloatingHeaderApp(),
);
final Finder headerText = find.text('SliverFloatingHeader\nScroll down a little to show\nScroll up a little to hide');
final double headerHeight = tester.getSize(headerText).height;
await tester.drag(find.byType(CustomScrollView), Offset(0, -2 * headerHeight));
await tester.pumpAndSettle();
expect(headerText, findsNothing);
await tester.drag(find.byType(CustomScrollView), Offset(0, 0.5 * headerHeight));
await tester.pumpAndSettle();
expect(headerText, findsOneWidget);
await tester.drag(find.byType(CustomScrollView), Offset(0, -0.5 * headerHeight));
await tester.pumpAndSettle();
expect(headerText, findsNothing);
});
}