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

A sliver that is pinned to the start of its `CustomScrollView` and reacts to scrolling by resizing between the intrinsic sizes of its min and max extent prototypes. The minimum and maximum sizes of this sliver are defined by `minExtentPrototype` and `maxExtentPrototype`, a pair of widgets that are laid out once. You can use `SizedBox` widgets to define the size limits. 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 minimum or maximum size. The sample shows how this sliver's two extent prototype properties can be used to create a resizing header whose minimum and maximum sizes match small and large configurations of the same header widget. https://github.com/flutter/flutter/assets/1377460/fa7ced98-9d92-4d13-b093-50392118c213 Related sliver utility PRs: https://github.com/flutter/flutter/pull/143538, https://github.com/flutter/flutter/pull/143196, https://github.com/flutter/flutter/pull/127340.
27 lines
1.0 KiB
Dart
27 lines
1.0 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_resizing_header.0.dart' as example;
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
testWidgets('SliverResizingHeader example', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
const example.SliverResizingHeaderApp(),
|
|
);
|
|
|
|
final Finder headerMaterial = find.text('SliverResizingHeader\nWith Two Optional\nLines of Text');
|
|
final double initialHeight = tester.getSize(headerMaterial).height;
|
|
|
|
await tester.drag(find.byType(CustomScrollView), const Offset(0, -200));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getSize(headerMaterial).height, lessThan(initialHeight / 2));
|
|
|
|
await tester.drag(find.byType(CustomScrollView), const Offset(0, 200));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.getSize(headerMaterial).height, initialHeight);
|
|
});
|
|
}
|