diff --git a/packages/flutter/lib/src/rendering/sliver.dart b/packages/flutter/lib/src/rendering/sliver.dart index c8c1f44bf8..57292985ba 100644 --- a/packages/flutter/lib/src/rendering/sliver.dart +++ b/packages/flutter/lib/src/rendering/sliver.dart @@ -1159,18 +1159,13 @@ abstract class RenderViewportBase2 0; diff --git a/packages/flutter/test/widgets/state_setting_in_scrollables_test.dart b/packages/flutter/test/widgets/state_setting_in_scrollables_test.dart index 7650484d2f..8acd4e22c5 100644 --- a/packages/flutter/test/widgets/state_setting_in_scrollables_test.dart +++ b/packages/flutter/test/widgets/state_setting_in_scrollables_test.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/foundation.dart' show defaultTargetPlatform; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart' hide TypeMatcher; @@ -12,22 +11,21 @@ class Foo extends StatefulWidget { } class FooState extends State { - final GlobalKey blockKey = new GlobalKey(); - GlobalKey scrollableKey = new GlobalKey(); + ScrollController scrollController = new ScrollController(); @override Widget build(BuildContext context) { return new LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { - return new ScrollConfiguration( - delegate: new FooScrollConfiguration(), - child: new Block( - scrollableKey: scrollableKey, + return new ScrollConfiguration2( + behavior: new FooScrollBehavior(), + child: new ListView( + controller: scrollController, children: [ new GestureDetector( onTap: () { setState(() { /* this is needed to trigger the original bug this is regression-testing */ }); - scrollableKey.currentState.scrollBy(200.0, duration: const Duration(milliseconds: 500)); + scrollController.animateTo(200.0, duration: const Duration(milliseconds: 500), curve: Curves.linear); }, child: new DecoratedBox( decoration: const BoxDecoration(backgroundColor: const Color(0)), @@ -74,25 +72,18 @@ class FooState extends State { } } -class FooScrollConfiguration extends ScrollConfigurationDelegate { +class FooScrollBehavior extends ScrollBehavior2 { @override - TargetPlatform get platform => defaultTargetPlatform; - - @override - ExtentScrollBehavior createScrollBehavior() => - new OverscrollWhenScrollableBehavior(platform: platform); - - @override - bool updateShouldNotify(FooScrollConfiguration old) => true; + bool shouldNotify(FooScrollBehavior old) => true; } void main() { - testWidgets('https://github.com/flutter/flutter/issues/5630', (WidgetTester tester) async { + testWidgets('Can animate scroll after setState', (WidgetTester tester) async { await tester.pumpWidget(new Foo()); - expect(tester.state(find.byType(Scrollable)).scrollOffset, 0.0); + expect(tester.state(find.byType(Scrollable2)).position.pixels, 0.0); await tester.tap(find.byType(GestureDetector).first); await tester.pump(); await tester.pump(const Duration(seconds: 1)); - expect(tester.state(find.byType(Scrollable)).scrollOffset, 200.0); + expect(tester.state(find.byType(Scrollable2)).position.pixels, 200.0); }); }