@@ -689,7 +689,7 @@ void main() {
689689 expect (fakeRefresh.called, isTrue);
690690 });
691691
692- testWidgets ('CustomRefreshIndicator - disallows indicator - glow' ,
692+ testWidgets ('CustomRefreshIndicator - disallows indicator - glow - leading ' ,
693693 (WidgetTester tester) async {
694694 bool glowAccepted = true ;
695695 ScrollNotification ? lastNotification;
@@ -737,6 +737,55 @@ void main() {
737737 expect (glowAccepted, isFalse);
738738 });
739739
740+ testWidgets ('CustomRefreshIndicator - disallows indicator - glow - trailing' ,
741+ (WidgetTester tester) async {
742+ bool glowAccepted = true ;
743+ ScrollNotification ? lastNotification;
744+
745+ await tester.pumpWidget (
746+ MaterialApp (
747+ home: CustomRefreshIndicator (
748+ leadingScrollIndicatorVisible: true ,
749+ trailingScrollIndicatorVisible: false ,
750+ builder: buildWithoutIndicator,
751+ onRefresh: fakeRefresh.instantRefresh,
752+ child: Builder (builder: (BuildContext context) {
753+ return NotificationListener <ScrollNotification >(
754+ onNotification: (ScrollNotification notification) {
755+ if (notification is OverscrollNotification &&
756+ lastNotification is ! OverscrollNotification ) {
757+ final OverscrollIndicatorNotification
758+ confirmationNotification =
759+ OverscrollIndicatorNotification (leading: false );
760+ confirmationNotification.dispatch (context);
761+ glowAccepted = confirmationNotification.accepted;
762+ }
763+ lastNotification = notification;
764+ return false ;
765+ },
766+ child: const DefaultList (itemsCount: 6 ),
767+ );
768+ }),
769+ ),
770+ ),
771+ );
772+
773+ expect (find.byType (StretchingOverscrollIndicator ), findsNothing);
774+ expect (find.byType (GlowingOverscrollIndicator ), findsOneWidget);
775+
776+ await tester.fling (find.text ('1' ), const Offset (0.0 , 300.0 ), 1000.0 );
777+ await tester.pump ();
778+
779+ // finish the scroll animation
780+ await tester.pump (const Duration (seconds: 1 ));
781+ // finish the indicator settle animation
782+ await tester.pump (const Duration (seconds: 1 ));
783+ // finish the indicator hide animation
784+ await tester.pump (const Duration (seconds: 1 ));
785+ expect (fakeRefresh.called, isTrue);
786+ expect (glowAccepted, isFalse);
787+ });
788+
740789 testWidgets ('CustomRefreshIndicator - disallows indicator - stretch' ,
741790 (WidgetTester tester) async {
742791 bool stretchAccepted = true ;
@@ -797,7 +846,7 @@ void main() {
797846 builder: buildWithoutIndicator,
798847 trigger: IndicatorTrigger .bothEdges,
799848 onRefresh: fakeRefresh.instantRefresh,
800- child: const DefaultList (itemsCount: 1 ),
849+ child: const DefaultList (itemsCount: 6 ),
801850 ),
802851 ),
803852 );
@@ -820,7 +869,11 @@ void main() {
820869 fakeRefresh.reset ();
821870
822871 // end edge
823- await tester.fling (find.text ('1' ), const Offset (0.0 , - 300.0 ), 1000.0 );
872+
873+ // scroll to end
874+ await tester.fling (find.text ('1' ), const Offset (0.0 , - 1000.0 ), 1000.0 );
875+ // trigger indicator
876+ await tester.fling (find.text ('6' ), const Offset (0.0 , - 300.0 ), 1000.0 );
824877 await tester.pump ();
825878 // finish the scroll animation
826879 await tester.pump (const Duration (seconds: 1 ));
@@ -912,4 +965,109 @@ void main() {
912965 expect (indicatorController.edge, isNull);
913966 expect (indicatorController.value, equals (0.0 ));
914967 });
968+
969+ testWidgets ('CustomRefreshIndicator - onStateChanged' ,
970+ (WidgetTester tester) async {
971+ final changes = < IndicatorStateChange > [];
972+ await tester.pumpWidget (
973+ MaterialApp (
974+ home: CustomRefreshIndicator (
975+ onStateChanged: (change) => changes.add (change),
976+ builder: buildWithoutIndicator,
977+ onRefresh: fakeRefresh.instantRefresh,
978+ child: const DefaultList (itemsCount: 1 ),
979+ ),
980+ ),
981+ );
982+
983+ // start edge
984+ await tester.fling (find.text ('1' ), const Offset (0.0 , 300.0 ), 1000.0 );
985+ await tester.pump ();
986+ // finish the scroll animation
987+ await tester.pump (const Duration (seconds: 1 ));
988+ // finish the indicator
989+ await tester.pump (const Duration (seconds: 1 ));
990+
991+ expect (changes, hasLength (5 ));
992+ expect (changes, [
993+ const IndicatorStateChange (
994+ IndicatorState .idle,
995+ IndicatorState .dragging,
996+ ),
997+ const IndicatorStateChange (
998+ IndicatorState .dragging,
999+ IndicatorState .armed,
1000+ ),
1001+ const IndicatorStateChange (
1002+ IndicatorState .armed,
1003+ IndicatorState .loading,
1004+ ),
1005+ const IndicatorStateChange (
1006+ IndicatorState .loading,
1007+ IndicatorState .hiding,
1008+ ),
1009+ const IndicatorStateChange (
1010+ IndicatorState .hiding,
1011+ IndicatorState .idle,
1012+ )
1013+ ]);
1014+
1015+ expect (fakeRefresh.called, isTrue);
1016+ });
1017+
1018+ testWidgets ('CustomRefreshIndicator - onStateChanged - with completed state' ,
1019+ (WidgetTester tester) async {
1020+ final changes = < IndicatorStateChange > [];
1021+ await tester.pumpWidget (
1022+ MaterialApp (
1023+ home: CustomRefreshIndicator (
1024+ onStateChanged: (change) => changes.add (change),
1025+ builder: buildWithoutIndicator,
1026+ onRefresh: fakeRefresh.instantRefresh,
1027+ completeStateDuration: const Duration (milliseconds: 300 ),
1028+ child: const DefaultList (itemsCount: 1 ),
1029+ ),
1030+ ),
1031+ );
1032+
1033+ // start edge
1034+ await tester.fling (find.text ('1' ), const Offset (0.0 , 300.0 ), 1000.0 );
1035+ await tester.pump ();
1036+ // finish the scroll animation
1037+ await tester.pump (const Duration (seconds: 1 ));
1038+ // wait for complete state
1039+ await tester.pump (const Duration (seconds: 1 ));
1040+ // finish the indicator
1041+ await tester.pump (const Duration (seconds: 1 ));
1042+
1043+ expect (changes, hasLength (6 ));
1044+ expect (changes, [
1045+ const IndicatorStateChange (
1046+ IndicatorState .idle,
1047+ IndicatorState .dragging,
1048+ ),
1049+ const IndicatorStateChange (
1050+ IndicatorState .dragging,
1051+ IndicatorState .armed,
1052+ ),
1053+ const IndicatorStateChange (
1054+ IndicatorState .armed,
1055+ IndicatorState .loading,
1056+ ),
1057+ const IndicatorStateChange (
1058+ IndicatorState .loading,
1059+ IndicatorState .complete,
1060+ ),
1061+ const IndicatorStateChange (
1062+ IndicatorState .complete,
1063+ IndicatorState .hiding,
1064+ ),
1065+ const IndicatorStateChange (
1066+ IndicatorState .hiding,
1067+ IndicatorState .idle,
1068+ )
1069+ ]);
1070+
1071+ expect (fakeRefresh.called, isTrue);
1072+ });
9151073}
0 commit comments