Commit 7b33efb6 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Revert "Fixed TrackingScrollController cleaning offset on position's detach (#11798)" (#11897)

This reverts commit ec25f6bd.
parent ec25f6bd
...@@ -15,4 +15,3 @@ Alexandre Ardhuin <alexandre.ardhuin@gmail.com> ...@@ -15,4 +15,3 @@ Alexandre Ardhuin <alexandre.ardhuin@gmail.com>
Luke Freeman <luke@goposse.com> Luke Freeman <luke@goposse.com>
Vincent Le Quéméner <eu.lequem@gmail.com> Vincent Le Quéméner <eu.lequem@gmail.com>
Mike Hoolehan <mike@hoolehan.com> Mike Hoolehan <mike@hoolehan.com>
German Saprykin <saprykin.h@gmail.com>
...@@ -323,7 +323,6 @@ class TrackingScrollController extends ScrollController { ...@@ -323,7 +323,6 @@ class TrackingScrollController extends ScrollController {
final Map<ScrollPosition, VoidCallback> _positionToListener = <ScrollPosition, VoidCallback>{}; final Map<ScrollPosition, VoidCallback> _positionToListener = <ScrollPosition, VoidCallback>{};
ScrollPosition _lastUpdated; ScrollPosition _lastUpdated;
double _lastUpdatedOffset;
/// The last [ScrollPosition] to change. Returns null if there aren't any /// The last [ScrollPosition] to change. Returns null if there aren't any
/// attached scroll positions, or there hasn't been any scrolling yet, or the /// attached scroll positions, or there hasn't been any scrolling yet, or the
...@@ -337,16 +336,13 @@ class TrackingScrollController extends ScrollController { ...@@ -337,16 +336,13 @@ class TrackingScrollController extends ScrollController {
/// ///
/// * [ScrollController.initialScrollOffset], which this overrides. /// * [ScrollController.initialScrollOffset], which this overrides.
@override @override
double get initialScrollOffset => _lastUpdatedOffset ?? super.initialScrollOffset; double get initialScrollOffset => _lastUpdated?.pixels ?? super.initialScrollOffset;
@override @override
void attach(ScrollPosition position) { void attach(ScrollPosition position) {
super.attach(position); super.attach(position);
assert(!_positionToListener.containsKey(position)); assert(!_positionToListener.containsKey(position));
_positionToListener[position] = () { _positionToListener[position] = () { _lastUpdated = position; };
_lastUpdated = position;
_lastUpdatedOffset = position.pixels;
};
position.addListener(_positionToListener[position]); position.addListener(_positionToListener[position]);
} }
...@@ -358,8 +354,6 @@ class TrackingScrollController extends ScrollController { ...@@ -358,8 +354,6 @@ class TrackingScrollController extends ScrollController {
_positionToListener.remove(position); _positionToListener.remove(position);
if (_lastUpdated == position) if (_lastUpdated == position)
_lastUpdated = null; _lastUpdated = null;
if (_positionToListener.isEmpty)
_lastUpdatedOffset = null;
} }
@override @override
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('TrackingScrollController saves offset',
(WidgetTester tester) async {
final TrackingScrollController controller = new TrackingScrollController();
await tester.pumpWidget(
new PageView.builder(
itemBuilder: (BuildContext context, int index) {
return new ListView(
controller: controller,
children: new List<Widget>.generate(
10,
(int i) => new Container(
height: 100.0, child: new Text("Page$index-Item$i")),
).toList());
},
),
);
expect(find.text('Page0-Item1'), findsOneWidget);
expect(find.text('Page1-Item1'), findsNothing);
expect(find.text('Page2-Item0'), findsNothing);
expect(find.text('Page2-Item1'), findsNothing);
controller.jumpTo(110.0);
await (tester.pumpAndSettle());
await tester.fling(
find.text('Page0-Item1'), const Offset(-100.0, 0.0), 10000.0);
await (tester.pumpAndSettle());
expect(find.text('Page0-Item1'), findsNothing);
expect(find.text('Page1-Item1'), findsOneWidget);
expect(find.text('Page2-Item0'), findsNothing);
expect(find.text('Page2-Item1'), findsNothing);
await tester.fling(
find.text('Page1-Item1'), const Offset(-100.0, 0.0), 10000.0);
await (tester.pumpAndSettle());
expect(find.text('Page0-Item1'), findsNothing);
expect(find.text('Page1-Item1'), findsNothing);
expect(find.text('Page2-Item0'), findsNothing);
expect(find.text('Page2-Item1'), findsOneWidget);
await tester.pumpWidget(new Text("Another page"));
expect(controller.initialScrollOffset, 0.0);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment