mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

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
31 lines
1.2 KiB
Dart
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);
|
|
});
|
|
}
|