Skip to content

Commit fcd90c0

Browse files
authored
ScrollPosition.jumpTo call notifyListeners twice (flutter#53425)
1 parent 560c722 commit fcd90c0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/flutter/lib/src/widgets/scroll_position_with_single_context.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ class ScrollPositionWithSingleContext extends ScrollPosition implements ScrollAc
198198
if (pixels != value) {
199199
final double oldPixels = pixels;
200200
forcePixels(value);
201-
notifyListeners();
202201
didStartScroll();
203202
didUpdateScrollPositionBy(pixels - oldPixels);
204203
didEndScroll();
@@ -213,7 +212,6 @@ class ScrollPositionWithSingleContext extends ScrollPosition implements ScrollAc
213212
if (pixels != value) {
214213
final double oldPixels = pixels;
215214
forcePixels(value);
216-
notifyListeners();
217215
didStartScroll();
218216
didUpdateScrollPositionBy(pixels - oldPixels);
219217
didEndScroll();

packages/flutter/test/widgets/scroll_position_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ Future<void> performTest(WidgetTester tester, bool maintainState) async {
141141
}
142142

143143
void main() {
144+
testWidgets('ScrollPosition jumpTo() doesn\'t call notifyListeners twice', (WidgetTester tester) async {
145+
int count = 0;
146+
await tester.pumpWidget(MaterialApp(
147+
home: ListView.builder(
148+
itemBuilder: (BuildContext context, int index) {
149+
return Text('$index', textDirection: TextDirection.ltr);
150+
},
151+
),
152+
));
153+
154+
final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
155+
position.addListener(() {
156+
count++;
157+
});
158+
position.jumpTo(100);
159+
160+
expect(count, 1);
161+
});
162+
144163
testWidgets('whether we remember our scroll position', (WidgetTester tester) async {
145164
await performTest(tester, true);
146165
await performTest(tester, false);

0 commit comments

Comments
 (0)