slivers_appbar_floating_test.dart 20.9 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
Ian Hickson's avatar
Ian Hickson committed
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6 7
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
Ian Hickson's avatar
Ian Hickson committed
8
import 'package:flutter/rendering.dart';
9
import 'package:flutter_test/flutter_test.dart';
Ian Hickson's avatar
Ian Hickson committed
10 11

void verifyPaintPosition(GlobalKey key, Offset ideal, bool visible) {
12
  final RenderSliver target = key.currentContext!.findRenderObject()! as RenderSliver;
Dan Field's avatar
Dan Field committed
13
  expect(target.parent, isA<RenderViewport>());
14
  final SliverPhysicalParentData parentData = target.parentData! as SliverPhysicalParentData;
15
  final Offset actual = parentData.paintOffset;
Ian Hickson's avatar
Ian Hickson committed
16
  expect(actual, ideal);
17
  final SliverGeometry geometry = target.geometry!;
Ian Hickson's avatar
Ian Hickson committed
18 19 20 21
  expect(geometry.visible, visible);
}

void verifyActualBoxPosition(WidgetTester tester, Finder finder, int index, Rect ideal) {
22
  final RenderBox box = tester.renderObjectList<RenderBox>(finder).elementAt(index);
23
  final Rect rect = Rect.fromPoints(box.localToGlobal(Offset.zero), box.localToGlobal(box.size.bottomRight(Offset.zero)));
Ian Hickson's avatar
Ian Hickson committed
24 25 26 27
  expect(rect, equals(ideal));
}

void main() {
28
  testWidgets("Sliver appbars - floating - scroll offset doesn't change", (WidgetTester tester) async {
Ian Hickson's avatar
Ian Hickson committed
29 30
    const double bigHeight = 1000.0;
    await tester.pumpWidget(
31
      Directionality(
32
        textDirection: TextDirection.ltr,
33
        child: CustomScrollView(
34 35
          slivers: <Widget>[
            const BigSliver(height: bigHeight),
36
            SliverPersistentHeader(delegate: TestDelegate(), floating: true),
37 38 39
            const BigSliver(height: bigHeight),
          ],
        ),
Ian Hickson's avatar
Ian Hickson committed
40 41
      ),
    );
42
    final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
43
    final double max = bigHeight * 2.0 + TestDelegate().maxExtent - 600.0; // 600 is the height of the test viewport
Ian Hickson's avatar
Ian Hickson committed
44 45 46 47 48
    assert(max < 10000.0);
    expect(max, 1600.0);
    expect(position.pixels, 0.0);
    expect(position.minScrollExtent, 0.0);
    expect(position.maxScrollExtent, max);
49
    position.animateTo(10000.0, curve: Curves.linear, duration: const Duration(minutes: 1));
50
    await tester.pumpAndSettle(const Duration(milliseconds: 50));
Ian Hickson's avatar
Ian Hickson committed
51 52 53 54 55 56
    expect(position.pixels, max);
    expect(position.minScrollExtent, 0.0);
    expect(position.maxScrollExtent, max);
  });

  testWidgets('Sliver appbars - floating - normal behavior works', (WidgetTester tester) async {
57
    final TestDelegate delegate = TestDelegate();
Ian Hickson's avatar
Ian Hickson committed
58 59 60
    const double bigHeight = 1000.0;
    GlobalKey key1, key2, key3;
    await tester.pumpWidget(
61
      Directionality(
62
        textDirection: TextDirection.ltr,
63
        child: CustomScrollView(
64
          slivers: <Widget>[
65 66 67
            BigSliver(key: key1 = GlobalKey(), height: bigHeight),
            SliverPersistentHeader(key: key2 = GlobalKey(), delegate: delegate, floating: true),
            BigSliver(key: key3 = GlobalKey(), height: bigHeight),
68 69
          ],
        ),
Ian Hickson's avatar
Ian Hickson committed
70 71
      ),
    );
72
    final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
Ian Hickson's avatar
Ian Hickson committed
73

74
    verifyPaintPosition(key1, Offset.zero, true);
75 76
    verifyPaintPosition(key2, const Offset(0.0, 1000.0), false);
    verifyPaintPosition(key3, const Offset(0.0, 1200.0), false);
Ian Hickson's avatar
Ian Hickson committed
77

78
    position.animateTo(bigHeight - 600.0 + delegate.maxExtent, curve: Curves.linear, duration: const Duration(minutes: 1));
79
    await tester.pumpAndSettle(const Duration(milliseconds: 1000));
80
    verifyPaintPosition(key1, Offset.zero, true);
81 82
    verifyPaintPosition(key2, Offset(0.0, 600.0 - delegate.maxExtent), true);
    verifyActualBoxPosition(tester, find.byType(Container), 0, Rect.fromLTWH(0.0, 600.0 - delegate.maxExtent, 800.0, delegate.maxExtent));
83
    verifyPaintPosition(key3, const Offset(0.0, 600.0), false);
Ian Hickson's avatar
Ian Hickson committed
84 85

    assert(delegate.maxExtent * 2.0 < 600.0); // make sure this fits on the test screen...
86
    position.animateTo(bigHeight - 600.0 + delegate.maxExtent * 2.0, curve: Curves.linear, duration: const Duration(minutes: 1));
87
    await tester.pumpAndSettle(const Duration(milliseconds: 1000));
88
    verifyPaintPosition(key1, Offset.zero, true);
89 90 91
    verifyPaintPosition(key2, Offset(0.0, 600.0 - delegate.maxExtent * 2.0), true);
    verifyActualBoxPosition(tester, find.byType(Container), 0, Rect.fromLTWH(0.0, 600.0 - delegate.maxExtent * 2.0, 800.0, delegate.maxExtent));
    verifyPaintPosition(key3, Offset(0.0, 600.0 - delegate.maxExtent), true);
Ian Hickson's avatar
Ian Hickson committed
92

93
    position.animateTo(bigHeight, curve: Curves.linear, duration: const Duration(minutes: 1));
94
    await tester.pumpAndSettle(const Duration(milliseconds: 1000));
95 96
    verifyPaintPosition(key1, Offset.zero, false);
    verifyPaintPosition(key2, Offset.zero, true);
97 98
    verifyActualBoxPosition(tester, find.byType(Container), 0, Rect.fromLTWH(0.0, 0.0, 800.0, delegate.maxExtent));
    verifyPaintPosition(key3, Offset(0.0, delegate.maxExtent), true);
Ian Hickson's avatar
Ian Hickson committed
99

100
    position.animateTo(bigHeight + delegate.maxExtent * 0.1, curve: Curves.linear, duration: const Duration(minutes: 1));
101
    await tester.pumpAndSettle(const Duration(milliseconds: 1000));
102 103
    verifyPaintPosition(key1, Offset.zero, false);
    verifyPaintPosition(key2, Offset.zero, true);
104 105
    verifyActualBoxPosition(tester, find.byType(Container), 0, Rect.fromLTWH(0.0, 0.0, 800.0, delegate.maxExtent * 0.9));
    verifyPaintPosition(key3, Offset(0.0, delegate.maxExtent * 0.9), true);
Ian Hickson's avatar
Ian Hickson committed
106

107
    position.animateTo(bigHeight + delegate.maxExtent * 0.5, curve: Curves.linear, duration: const Duration(minutes: 1));
108
    await tester.pumpAndSettle(const Duration(milliseconds: 1000));
109 110
    verifyPaintPosition(key1, Offset.zero, false);
    verifyPaintPosition(key2, Offset.zero, true);
111 112
    verifyActualBoxPosition(tester, find.byType(Container), 0, Rect.fromLTWH(0.0, 0.0, 800.0, delegate.maxExtent * 0.5));
    verifyPaintPosition(key3, Offset(0.0, delegate.maxExtent * 0.5), true);
Ian Hickson's avatar
Ian Hickson committed
113

114
    position.animateTo(bigHeight + delegate.maxExtent * 0.9, curve: Curves.linear, duration: const Duration(minutes: 1));
115
    await tester.pumpAndSettle(const Duration(milliseconds: 1000));
116 117
    verifyPaintPosition(key1, Offset.zero, false);
    verifyPaintPosition(key2, Offset.zero, true);
118 119
    verifyActualBoxPosition(tester, find.byType(Container), 0, Rect.fromLTWH(0.0, -delegate.maxExtent * 0.4, 800.0, delegate.maxExtent * 0.5));
    verifyPaintPosition(key3, Offset(0.0, delegate.maxExtent * 0.1), true);
Ian Hickson's avatar
Ian Hickson committed
120

121
    position.animateTo(bigHeight + delegate.maxExtent * 2.0, curve: Curves.linear, duration: const Duration(minutes: 1));
122
    await tester.pumpAndSettle(const Duration(milliseconds: 1000));
123 124 125
    verifyPaintPosition(key1, Offset.zero, false);
    verifyPaintPosition(key2, Offset.zero, false);
    verifyPaintPosition(key3, Offset.zero, true);
Ian Hickson's avatar
Ian Hickson committed
126 127 128
  });

  testWidgets('Sliver appbars - floating - no floating behavior when animating', (WidgetTester tester) async {
129
    final TestDelegate delegate = TestDelegate();
Ian Hickson's avatar
Ian Hickson committed
130 131 132
    const double bigHeight = 1000.0;
    GlobalKey key1, key2, key3;
    await tester.pumpWidget(
133
      Directionality(
134
        textDirection: TextDirection.ltr,
135
        child: CustomScrollView(
136
          slivers: <Widget>[
137 138 139
            BigSliver(key: key1 = GlobalKey(), height: bigHeight),
            SliverPersistentHeader(key: key2 = GlobalKey(), delegate: delegate, floating: true),
            BigSliver(key: key3 = GlobalKey(), height: bigHeight),
140 141
          ],
        ),
Ian Hickson's avatar
Ian Hickson committed
142 143
      ),
    );
144
    final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
Ian Hickson's avatar
Ian Hickson committed
145

146
    verifyPaintPosition(key1, Offset.zero, true);
147 148
    verifyPaintPosition(key2, const Offset(0.0, 1000.0), false);
    verifyPaintPosition(key3, const Offset(0.0, 1200.0), false);
Ian Hickson's avatar
Ian Hickson committed
149

150
    position.animateTo(bigHeight + delegate.maxExtent * 2.0, curve: Curves.linear, duration: const Duration(minutes: 1));
151
    await tester.pumpAndSettle(const Duration(milliseconds: 1000));
152 153 154
    verifyPaintPosition(key1, Offset.zero, false);
    verifyPaintPosition(key2, Offset.zero, false);
    verifyPaintPosition(key3, Offset.zero, true);
Ian Hickson's avatar
Ian Hickson committed
155

156
    position.animateTo(bigHeight + delegate.maxExtent * 1.9, curve: Curves.linear, duration: const Duration(minutes: 1));
157
    await tester.pumpAndSettle(const Duration(milliseconds: 1000));
158 159 160
    verifyPaintPosition(key1, Offset.zero, false);
    verifyPaintPosition(key2, Offset.zero, false);
    verifyPaintPosition(key3, Offset.zero, true);
Ian Hickson's avatar
Ian Hickson committed
161 162 163
  });

  testWidgets('Sliver appbars - floating - floating behavior when dragging down', (WidgetTester tester) async {
164
    final TestDelegate delegate = TestDelegate();
Ian Hickson's avatar
Ian Hickson committed
165 166 167
    const double bigHeight = 1000.0;
    GlobalKey key1, key2, key3;
    await tester.pumpWidget(
168
      Directionality(
169
        textDirection: TextDirection.ltr,
170
        child: CustomScrollView(
171
          slivers: <Widget>[
172 173 174
            BigSliver(key: key1 = GlobalKey(), height: bigHeight),
            SliverPersistentHeader(key: key2 = GlobalKey(), delegate: delegate, floating: true),
            BigSliver(key: key3 = GlobalKey(), height: bigHeight),
175 176
          ],
        ),
Ian Hickson's avatar
Ian Hickson committed
177 178
      ),
    );
179
    final ScrollPositionWithSingleContext position = tester.state<ScrollableState>(find.byType(Scrollable)).position as ScrollPositionWithSingleContext;
Ian Hickson's avatar
Ian Hickson committed
180

181
    verifyPaintPosition(key1, Offset.zero, true);
182 183
    verifyPaintPosition(key2, const Offset(0.0, 1000.0), false);
    verifyPaintPosition(key3, const Offset(0.0, 1200.0), false);
Ian Hickson's avatar
Ian Hickson committed
184

185
    position.animateTo(bigHeight + delegate.maxExtent * 2.0, curve: Curves.linear, duration: const Duration(minutes: 1));
186
    await tester.pumpAndSettle(const Duration(milliseconds: 1000));
187 188 189
    verifyPaintPosition(key1, Offset.zero, false);
    verifyPaintPosition(key2, Offset.zero, false);
    verifyPaintPosition(key3, Offset.zero, true);
Ian Hickson's avatar
Ian Hickson committed
190

191
    position.animateTo(bigHeight + delegate.maxExtent * 1.9, curve: Curves.linear, duration: const Duration(minutes: 1));
192
    position.updateUserScrollDirection(ScrollDirection.forward);
193
    await tester.pumpAndSettle(const Duration(milliseconds: 1000));
194 195
    verifyPaintPosition(key1, Offset.zero, false);
    verifyPaintPosition(key2, Offset.zero, true);
196
    verifyActualBoxPosition(tester, find.byType(Container), 0, Rect.fromLTWH(0.0, -delegate.maxExtent * 0.4, 800.0, delegate.maxExtent * 0.5));
197
    verifyPaintPosition(key3, Offset.zero, true);
Ian Hickson's avatar
Ian Hickson committed
198
  });
199 200 201

  testWidgets('Sliver appbars - floating - overscroll gap is below header', (WidgetTester tester) async {
    await tester.pumpWidget(
202
      Directionality(
203
        textDirection: TextDirection.ltr,
204
        child: CustomScrollView(
205 206
          physics: const BouncingScrollPhysics(),
          slivers: <Widget>[
207
            SliverPersistentHeader(delegate: TestDelegate(), floating: true),
208
            SliverList(
209
              delegate: SliverChildListDelegate(<Widget>[
210
                const SizedBox(
211
                  height: 300.0,
212
                  child: Text('X'),
213 214 215 216 217
                ),
              ]),
            ),
          ],
        ),
218 219 220
      ),
    );

221 222
    expect(tester.getTopLeft(find.byType(Container)), Offset.zero);
    expect(tester.getTopLeft(find.text('X')), const Offset(0.0, 200.0));
223

224
    final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
225 226 227
    position.jumpTo(-50.0);
    await tester.pump();

228 229
    expect(tester.getTopLeft(find.byType(Container)), Offset.zero);
    expect(tester.getTopLeft(find.text('X')), const Offset(0.0, 250.0));
230
  });
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454

  group('Pointer scrolled floating', () {
    Widget buildTest(Widget sliver) {
      return MaterialApp(
        home: CustomScrollView(
          slivers: <Widget>[
            sliver,
            SliverFixedExtentList(
              itemExtent: 50.0,
              delegate: SliverChildBuilderDelegate(
                  (BuildContext context, int index) => Text('Item $index'),
                childCount: 30,
              )
            ),
          ],
        ),
      );
    }

    void verifyGeometry({
      required GlobalKey key,
      required bool visible,
      required double paintExtent
    }) {
      final RenderSliver target = key.currentContext!.findRenderObject()! as RenderSliver;
      final SliverGeometry geometry = target.geometry!;
      expect(geometry.visible, visible);
      expect(geometry.paintExtent, paintExtent);
    }

    testWidgets('SliverAppBar', (WidgetTester tester) async {
      final GlobalKey appBarKey = GlobalKey();
      await tester.pumpWidget(buildTest(SliverAppBar(
        key: appBarKey,
        floating: true,
        title: const Text('Test Title'),
      )));

      expect(find.text('Test Title'), findsOneWidget);
      expect(find.text('Item 1'), findsOneWidget);
      expect(find.text('Item 5'), findsOneWidget);
      expect(
        tester.renderObject<RenderBox>(find.byType(AppBar)).size.height,
        56.0,
      );
      verifyGeometry(key: appBarKey, visible: true, paintExtent: 56.0);

      // Pointer scroll the app bar away, we will scroll back less to validate the
      // app bar floats back in.
      final Offset point1 = tester.getCenter(find.text('Item 5'));
      final TestPointer testPointer = TestPointer(1, ui.PointerDeviceKind.mouse);
      testPointer.hover(point1);
      await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, 300.0)));
      await tester.pump();
      expect(find.text('Test Title'), findsNothing);
      expect(find.text('Item 1'), findsNothing);
      expect(find.text('Item 5'), findsOneWidget);
      verifyGeometry(key: appBarKey, paintExtent: 0.0, visible: false);

      // Scroll back to float in appbar
      await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, -50.0)));
      await tester.pump();
      expect(find.text('Test Title'), findsOneWidget);
      expect(find.text('Item 1'), findsNothing);
      expect(find.text('Item 5'), findsOneWidget);
      expect(
        tester.renderObject<RenderBox>(find.byType(AppBar)).size.height,
        56.0,
      );
      verifyGeometry(key: appBarKey, paintExtent: 50.0, visible: true);

      // Float the rest of the way in.
      await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, -250.0)));
      await tester.pump();
      expect(find.text('Test Title'), findsOneWidget);
      expect(find.text('Item 1'), findsOneWidget);
      expect(find.text('Item 5'), findsOneWidget);
      expect(
        tester.renderObject<RenderBox>(find.byType(AppBar)).size.height,
        56.0,
      );
      verifyGeometry(key: appBarKey, paintExtent: 56.0, visible: true);
    });

    testWidgets('SliverPersistentHeader', (WidgetTester tester) async {
      final GlobalKey headerKey = GlobalKey();
      await tester.pumpWidget(buildTest(SliverPersistentHeader(
        key: headerKey,
        floating: true,
        delegate: HeaderDelegate(),
      )));

      expect(find.text('Test Title'), findsOneWidget);
      expect(find.text('Item 1'), findsOneWidget);
      expect(find.text('Item 5'), findsOneWidget);
      verifyGeometry(key: headerKey, visible: true, paintExtent: 56.0);

      // Pointer scroll the app bar away, we will scroll back less to validate the
      // app bar floats back in.
      final Offset point1 = tester.getCenter(find.text('Item 5'));
      final TestPointer testPointer = TestPointer(1, ui.PointerDeviceKind.mouse);
      testPointer.hover(point1);
      await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, 300.0)));
      await tester.pump();
      expect(find.text('Test Title'), findsNothing);
      expect(find.text('Item 1'), findsNothing);
      expect(find.text('Item 5'), findsOneWidget);
      verifyGeometry(key: headerKey, paintExtent: 0.0, visible: false);

      // Scroll back to float in appbar
      await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, -50.0)));
      await tester.pump();
      expect(find.text('Test Title'), findsOneWidget);
      expect(find.text('Item 1'), findsNothing);
      expect(find.text('Item 5'), findsOneWidget);
      verifyGeometry(key: headerKey, paintExtent: 50.0, visible: true);

      // Float the rest of the way in.
      await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, -250.0)));
      await tester.pump();
      expect(find.text('Test Title'), findsOneWidget);
      expect(find.text('Item 1'), findsOneWidget);
      expect(find.text('Item 5'), findsOneWidget);
      verifyGeometry(key: headerKey, paintExtent: 56.0, visible: true);
    });

    testWidgets('and snapping SliverAppBar', (WidgetTester tester) async {
      final GlobalKey appBarKey = GlobalKey();
      await tester.pumpWidget(buildTest(SliverAppBar(
        key: appBarKey,
        floating: true,
        snap: true,
        title: const Text('Test Title'),
      )));

      expect(find.text('Test Title'), findsOneWidget);
      expect(find.text('Item 1'), findsOneWidget);
      expect(find.text('Item 5'), findsOneWidget);
      expect(
        tester.renderObject<RenderBox>(find.byType(AppBar)).size.height,
        56.0,
      );
      verifyGeometry(key: appBarKey, visible: true, paintExtent: 56.0);

      // Pointer scroll the app bar away, we will scroll back less to validate the
      // app bar floats back in and then snaps to full size.
      final Offset point1 = tester.getCenter(find.text('Item 5'));
      final TestPointer testPointer = TestPointer(1, ui.PointerDeviceKind.mouse);
      testPointer.hover(point1);
      await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, 300.0)));
      await tester.pump();
      expect(find.text('Test Title'), findsNothing);
      expect(find.text('Item 1'), findsNothing);
      expect(find.text('Item 5'), findsOneWidget);
      verifyGeometry(key: appBarKey, paintExtent: 0.0, visible: false);

      // Scroll back to float in appbar
      await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, -30.0)));
      await tester.pump();
      expect(find.text('Test Title'), findsOneWidget);
      expect(find.text('Item 1'), findsNothing);
      expect(find.text('Item 5'), findsOneWidget);
      expect(
        tester.renderObject<RenderBox>(find.byType(AppBar)).size.height,
        56.0,
      );
      verifyGeometry(key: appBarKey, paintExtent: 30.0, visible: true);
      await tester.pumpAndSettle();
      // The snap animation should have completed and the app bar should be
      // fully expanded.
      expect(find.text('Test Title'), findsOneWidget);
      expect(find.text('Item 1'), findsNothing);
      expect(find.text('Item 5'), findsOneWidget);
      expect(
        tester.renderObject<RenderBox>(find.byType(AppBar)).size.height,
        56.0,
      );
      verifyGeometry(key: appBarKey, paintExtent: 56.0, visible: true);


      // Float back out a bit and trigger snap close animation.
      await tester.sendEventToBinding(testPointer.scroll(const Offset(0.0, 50.0)));
      await tester.pump();
      expect(find.text('Test Title'), findsOneWidget);
      expect(find.text('Item 1'), findsNothing);
      expect(find.text('Item 5'), findsOneWidget);
      expect(
        tester.renderObject<RenderBox>(find.byType(AppBar)).size.height,
        56.0,
      );
      verifyGeometry(key: appBarKey, paintExtent: 6.0, visible: true);
      await tester.pumpAndSettle();
      // The snap animation should have completed and the app bar should no
      // longer be visible.
      expect(find.text('Test Title'), findsNothing);
      expect(find.text('Item 1'), findsNothing);
      expect(find.text('Item 5'), findsOneWidget);
      expect(
        find.byType(AppBar),
        findsNothing,
      );
      verifyGeometry(key: appBarKey, paintExtent: 0.0, visible: false);
    });
  });
}

class HeaderDelegate extends SliverPersistentHeaderDelegate {
  @override
  Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
    return Container(
      height: 56,
      color: Colors.red,
      child: const Text('Test Title'),
    );
  }

  @override
  double get maxExtent => 56;

  @override
  double get minExtent => 56;

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => false;
Ian Hickson's avatar
Ian Hickson committed
455 456
}

457
class TestDelegate extends SliverPersistentHeaderDelegate {
Ian Hickson's avatar
Ian Hickson committed
458 459 460 461
  @override
  double get maxExtent => 200.0;

  @override
462 463 464 465
  double get minExtent => 100.0;

  @override
  Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
466
    return Container(constraints: BoxConstraints(minHeight: minExtent, maxHeight: maxExtent));
Ian Hickson's avatar
Ian Hickson committed
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
  }

  @override
  bool shouldRebuild(TestDelegate oldDelegate) => false;
}


class RenderBigSliver extends RenderSliver {
  RenderBigSliver(double height) : _height = height;

  double get height => _height;
  double _height;
  set height(double value) {
    if (value == _height)
      return;
    _height = value;
    markNeedsLayout();
  }

486
  double get paintExtent => (height - constraints.scrollOffset).clamp(0.0, constraints.remainingPaintExtent);
Ian Hickson's avatar
Ian Hickson committed
487 488 489

  @override
  void performLayout() {
490
    geometry = SliverGeometry(
Ian Hickson's avatar
Ian Hickson committed
491 492 493 494 495 496 497 498
      scrollExtent: height,
      paintExtent: paintExtent,
      maxPaintExtent: height,
    );
  }
}

class BigSliver extends LeafRenderObjectWidget {
499
  const BigSliver({ Key? key, required this.height }) : super(key: key);
Ian Hickson's avatar
Ian Hickson committed
500 501 502 503 504

  final double height;

  @override
  RenderBigSliver createRenderObject(BuildContext context) {
505
    return RenderBigSliver(height);
Ian Hickson's avatar
Ian Hickson committed
506 507 508 509 510 511 512
  }

  @override
  void updateRenderObject(BuildContext context, RenderBigSliver renderObject) {
    renderObject.height = height;
  }
}