|
5 | 5 | import 'dart:math' as math; |
6 | 6 |
|
7 | 7 | import 'package:flutter/foundation.dart'; |
| 8 | +import 'package:flutter/gestures.dart' show HitTestEntry, HitTestResult; |
8 | 9 | import 'package:flutter/widgets.dart'; |
9 | 10 | import 'package:flutter_test/flutter_test.dart'; |
10 | 11 |
|
@@ -593,6 +594,199 @@ void main() { |
593 | 594 | }), |
594 | 595 | ); |
595 | 596 |
|
| 597 | + testWidgets( |
| 598 | + 'child stretches into overscroll that exceeds precedingScrollExtent', |
| 599 | + (WidgetTester tester) async { |
| 600 | + // Regression test for https://github.com/flutter/flutter/issues/141077. |
| 601 | + final controller = ScrollController(); |
| 602 | + addTearDown(controller.dispose); |
| 603 | + final slivers = <Widget>[ |
| 604 | + sliverBox, |
| 605 | + const SliverFillRemaining( |
| 606 | + hasScrollBody: false, |
| 607 | + fillOverscroll: true, |
| 608 | + child: SizedBox.expand( |
| 609 | + child: ColoredBox(key: ValueKey<String>('fill'), color: _debugRed), |
| 610 | + ), |
| 611 | + ), |
| 612 | + ]; |
| 613 | + await tester.pumpWidget(boilerplate(slivers, controller: controller)); |
| 614 | + expect( |
| 615 | + tester.getRect(find.byKey(const ValueKey<String>('fill'))), |
| 616 | + const Rect.fromLTRB(0.0, 150.0, 800.0, 600.0), |
| 617 | + ); |
| 618 | + |
| 619 | + // Overscroll by 200: the preceding box frees up 150 of paint room |
| 620 | + // and the remaining 50 become this sliver's scrollOffset. |
| 621 | + controller.jumpTo(200.0); |
| 622 | + await tester.pump(); |
| 623 | + |
| 624 | + final Rect rect = tester.getRect(find.byKey(const ValueKey<String>('fill'))); |
| 625 | + expect(rect.bottom, 600.0); |
| 626 | + expect(rect.height, 650.0); |
| 627 | + |
| 628 | + controller.jumpTo(0.0); |
| 629 | + await tester.pump(); |
| 630 | + expect( |
| 631 | + tester.getRect(find.byKey(const ValueKey<String>('fill'))), |
| 632 | + const Rect.fromLTRB(0.0, 150.0, 800.0, 600.0), |
| 633 | + ); |
| 634 | + }, |
| 635 | + variant: const TargetPlatformVariant(<TargetPlatform>{ |
| 636 | + TargetPlatform.iOS, |
| 637 | + TargetPlatform.macOS, |
| 638 | + }), |
| 639 | + ); |
| 640 | + |
| 641 | + testWidgets( |
| 642 | + 'lone child stretches to cover the whole overscroll', |
| 643 | + (WidgetTester tester) async { |
| 644 | + // Regression test for https://github.com/flutter/flutter/issues/141077. |
| 645 | + final controller = ScrollController(); |
| 646 | + addTearDown(controller.dispose); |
| 647 | + final slivers = <Widget>[ |
| 648 | + const SliverFillRemaining( |
| 649 | + hasScrollBody: false, |
| 650 | + fillOverscroll: true, |
| 651 | + child: SizedBox.expand( |
| 652 | + child: ColoredBox(key: ValueKey<String>('fill'), color: _debugRed), |
| 653 | + ), |
| 654 | + ), |
| 655 | + ]; |
| 656 | + await tester.pumpWidget(boilerplate(slivers, controller: controller)); |
| 657 | + expect( |
| 658 | + tester.getRect(find.byKey(const ValueKey<String>('fill'))), |
| 659 | + const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0), |
| 660 | + ); |
| 661 | + |
| 662 | + controller.jumpTo(50.0); |
| 663 | + await tester.pump(); |
| 664 | + |
| 665 | + final Rect rect = tester.getRect(find.byKey(const ValueKey<String>('fill'))); |
| 666 | + expect(rect.bottom, 600.0); |
| 667 | + expect(rect.height, 650.0); |
| 668 | + |
| 669 | + controller.jumpTo(0.0); |
| 670 | + await tester.pump(); |
| 671 | + expect( |
| 672 | + tester.getRect(find.byKey(const ValueKey<String>('fill'))), |
| 673 | + const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0), |
| 674 | + ); |
| 675 | + }, |
| 676 | + variant: const TargetPlatformVariant(<TargetPlatform>{ |
| 677 | + TargetPlatform.iOS, |
| 678 | + TargetPlatform.macOS, |
| 679 | + }), |
| 680 | + ); |
| 681 | + |
| 682 | + testWidgets( |
| 683 | + 'child in a reversed scroll view stretches towards the leading edge', |
| 684 | + (WidgetTester tester) async { |
| 685 | + // Regression test for https://github.com/flutter/flutter/issues/141077. |
| 686 | + final controller = ScrollController(); |
| 687 | + addTearDown(controller.dispose); |
| 688 | + await tester.pumpWidget( |
| 689 | + TestWidgetsApp( |
| 690 | + home: CustomScrollView( |
| 691 | + reverse: true, |
| 692 | + controller: controller, |
| 693 | + slivers: const <Widget>[ |
| 694 | + SliverFillRemaining( |
| 695 | + hasScrollBody: false, |
| 696 | + fillOverscroll: true, |
| 697 | + child: SizedBox.expand( |
| 698 | + child: ColoredBox(key: ValueKey<String>('fill'), color: _debugRed), |
| 699 | + ), |
| 700 | + ), |
| 701 | + ], |
| 702 | + ), |
| 703 | + ), |
| 704 | + ); |
| 705 | + expect( |
| 706 | + tester.getRect(find.byKey(const ValueKey<String>('fill'))), |
| 707 | + const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0), |
| 708 | + ); |
| 709 | + |
| 710 | + controller.jumpTo(50.0); |
| 711 | + await tester.pump(); |
| 712 | + |
| 713 | + final Rect rect = tester.getRect(find.byKey(const ValueKey<String>('fill'))); |
| 714 | + expect(rect.top, 0.0); |
| 715 | + expect(rect.height, 650.0); |
| 716 | + |
| 717 | + // The stretched region hit tests to the child, matching where it |
| 718 | + // is painted. |
| 719 | + final HitTestResult hitTestResult = tester.hitTestOnBinding(const Offset(400.0, 25.0)); |
| 720 | + expect( |
| 721 | + hitTestResult.path.any( |
| 722 | + (HitTestEntry entry) => |
| 723 | + entry.target == tester.renderObject(find.byKey(const ValueKey<String>('fill'))), |
| 724 | + ), |
| 725 | + isTrue, |
| 726 | + ); |
| 727 | + |
| 728 | + controller.jumpTo(0.0); |
| 729 | + await tester.pump(); |
| 730 | + expect( |
| 731 | + tester.getRect(find.byKey(const ValueKey<String>('fill'))), |
| 732 | + const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0), |
| 733 | + ); |
| 734 | + }, |
| 735 | + variant: const TargetPlatformVariant(<TargetPlatform>{ |
| 736 | + TargetPlatform.iOS, |
| 737 | + TargetPlatform.macOS, |
| 738 | + }), |
| 739 | + ); |
| 740 | + |
| 741 | + testWidgets( |
| 742 | + 'child in a reversed horizontal scroll view stretches towards the leading edge', |
| 743 | + (WidgetTester tester) async { |
| 744 | + // Regression test for https://github.com/flutter/flutter/issues/141077. |
| 745 | + final controller = ScrollController(); |
| 746 | + addTearDown(controller.dispose); |
| 747 | + await tester.pumpWidget( |
| 748 | + TestWidgetsApp( |
| 749 | + home: CustomScrollView( |
| 750 | + scrollDirection: Axis.horizontal, |
| 751 | + reverse: true, |
| 752 | + controller: controller, |
| 753 | + slivers: const <Widget>[ |
| 754 | + SliverFillRemaining( |
| 755 | + hasScrollBody: false, |
| 756 | + fillOverscroll: true, |
| 757 | + child: SizedBox.expand( |
| 758 | + child: ColoredBox(key: ValueKey<String>('fill'), color: _debugRed), |
| 759 | + ), |
| 760 | + ), |
| 761 | + ], |
| 762 | + ), |
| 763 | + ), |
| 764 | + ); |
| 765 | + expect( |
| 766 | + tester.getRect(find.byKey(const ValueKey<String>('fill'))), |
| 767 | + const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0), |
| 768 | + ); |
| 769 | + |
| 770 | + controller.jumpTo(50.0); |
| 771 | + await tester.pump(); |
| 772 | + |
| 773 | + final Rect rect = tester.getRect(find.byKey(const ValueKey<String>('fill'))); |
| 774 | + expect(rect.left, 0.0); |
| 775 | + expect(rect.width, 850.0); |
| 776 | + |
| 777 | + controller.jumpTo(0.0); |
| 778 | + await tester.pump(); |
| 779 | + expect( |
| 780 | + tester.getRect(find.byKey(const ValueKey<String>('fill'))), |
| 781 | + const Rect.fromLTRB(0.0, 0.0, 800.0, 600.0), |
| 782 | + ); |
| 783 | + }, |
| 784 | + variant: const TargetPlatformVariant(<TargetPlatform>{ |
| 785 | + TargetPlatform.iOS, |
| 786 | + TargetPlatform.macOS, |
| 787 | + }), |
| 788 | + ); |
| 789 | + |
596 | 790 | testWidgets( |
597 | 791 | 'child with smaller size is overridden and sized by extent and overscroll', |
598 | 792 | (WidgetTester tester) async { |
|
0 commit comments