flutter/examples/api/test/widgets/sliver/sliver_floating_header.0_test.dart
Hans Muller d1e150099e
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
2024-07-03 19:52:52 +00:00

31 lines
1.2 KiB
Dart

// 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);
});
}