ScrollPosition.jumpTo call notifyListeners twice (#53425)

This commit is contained in:
nujz 2020-04-01 02:26:02 +08:00 committed by GitHub
parent 560c72287b
commit fcd90c0a51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -198,7 +198,6 @@ class ScrollPositionWithSingleContext extends ScrollPosition implements ScrollAc
if (pixels != value) {
final double oldPixels = pixels;
forcePixels(value);
notifyListeners();
didStartScroll();
didUpdateScrollPositionBy(pixels - oldPixels);
didEndScroll();
@ -213,7 +212,6 @@ class ScrollPositionWithSingleContext extends ScrollPosition implements ScrollAc
if (pixels != value) {
final double oldPixels = pixels;
forcePixels(value);
notifyListeners();
didStartScroll();
didUpdateScrollPositionBy(pixels - oldPixels);
didEndScroll();

View File

@ -141,6 +141,25 @@ Future<void> performTest(WidgetTester tester, bool maintainState) async {
}
void main() {
testWidgets('ScrollPosition jumpTo() doesn\'t call notifyListeners twice', (WidgetTester tester) async {
int count = 0;
await tester.pumpWidget(MaterialApp(
home: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return Text('$index', textDirection: TextDirection.ltr);
},
),
));
final ScrollPosition position = tester.state<ScrollableState>(find.byType(Scrollable)).position;
position.addListener(() {
count++;
});
position.jumpTo(100);
expect(count, 1);
});
testWidgets('whether we remember our scroll position', (WidgetTester tester) async {
await performTest(tester, true);
await performTest(tester, false);