Skip to content

Commit e5b070b

Browse files
author
Kamil Klyta
committed
Add BouncingPhysics tests
1 parent afbdb58 commit e5b070b

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

lib/src/custom_refresh_indicator.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,17 @@ class CustomRefreshIndicatorState extends State<CustomRefreshIndicator>
279279
bool _handleScrollUpdateNotification(ScrollUpdateNotification notification) {
280280
// Calculate the edge if not defined and possible.
281281
// This may apply to two-way lists on the iOS platform with bouncing physics.
282-
if (!controller.hasEdge) {
282+
if (!controller.hasEdge && notification.scrollDelta != null) {
283283
if (notification.metrics.extentBefore == 0 &&
284-
notification.scrollDelta?.isNegative == true) {
285-
controller.setIndicatorEdge(IndicatorEdge.start);
284+
notification.scrollDelta!.isNegative) {
285+
controller
286+
..setIndicatorEdge(IndicatorEdge.start)
287+
..setIndicatorState(IndicatorState.dragging);
286288
} else if (notification.metrics.extentAfter == 0 &&
287-
notification.scrollDelta?.isNegative == false) {
288-
controller.setIndicatorEdge(IndicatorEdge.end);
289+
!notification.scrollDelta!.isNegative) {
290+
controller
291+
..setIndicatorEdge(IndicatorEdge.end)
292+
..setIndicatorState(IndicatorState.dragging);
289293
}
290294
}
291295

test/src/custom_refresh_indicator_test.dart

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,4 +1070,53 @@ void main() {
10701070

10711071
expect(fakeRefresh.called, isTrue);
10721072
});
1073+
1074+
testWidgets(
1075+
'CustomRefreshIndicator - BouncingPhysics - start from scroll update notification',
1076+
(WidgetTester tester) async {
1077+
final indicatorController = IndicatorController();
1078+
final scrollController = ScrollController(initialScrollOffset: 0);
1079+
await tester.pumpWidget(
1080+
MaterialApp(
1081+
home: CustomRefreshIndicator(
1082+
controller: indicatorController,
1083+
builder: buildWithoutIndicator,
1084+
trigger: IndicatorTrigger.bothEdges,
1085+
onRefresh: fakeRefresh.instantRefresh,
1086+
child: DefaultList(
1087+
itemsCount: 1,
1088+
controller: scrollController,
1089+
physics: const AlwaysScrollableScrollPhysics(
1090+
parent: BouncingScrollPhysics()),
1091+
),
1092+
),
1093+
),
1094+
);
1095+
1096+
// start edge
1097+
await tester.fling(find.text('1'), const Offset(0.0, 300.0), 1000.0);
1098+
await tester.pump();
1099+
// finish the scroll animation
1100+
await tester.pump(const Duration(seconds: 1));
1101+
// wait for complete state
1102+
await tester.pump(const Duration(seconds: 1));
1103+
// finish the indicator
1104+
await tester.pump(const Duration(seconds: 1));
1105+
1106+
expect(fakeRefresh.called, isTrue);
1107+
fakeRefresh.reset();
1108+
expect(fakeRefresh.called, isFalse);
1109+
1110+
// end edge
1111+
await tester.fling(find.text('1'), const Offset(0.0, -300.0), 1000.0);
1112+
await tester.pump();
1113+
// finish the scroll animation
1114+
await tester.pump(const Duration(seconds: 1));
1115+
// wait for complete state
1116+
await tester.pump(const Duration(seconds: 1));
1117+
// finish the indicator
1118+
await tester.pump(const Duration(seconds: 1));
1119+
1120+
expect(fakeRefresh.called, isTrue);
1121+
});
10731122
}

0 commit comments

Comments
 (0)