diff --git a/packages/flutter/lib/src/widgets/scrollable.dart b/packages/flutter/lib/src/widgets/scrollable.dart index 80a7ae0a42..d4d4dd839b 100644 --- a/packages/flutter/lib/src/widgets/scrollable.dart +++ b/packages/flutter/lib/src/widgets/scrollable.dart @@ -854,7 +854,7 @@ class Block extends StatelessWidget { if (padding != null) contents = new Padding(padding: padding, child: contents); return new ScrollableViewport( - key: scrollableKey, + scrollableKey: scrollableKey, initialScrollOffset: initialScrollOffset, scrollDirection: scrollDirection, scrollAnchor: scrollAnchor, diff --git a/packages/flutter/test/widget/block_test.dart b/packages/flutter/test/widget/block_test.dart index 2fbbf01a83..c7f075e7ab 100644 --- a/packages/flutter/test/widget/block_test.dart +++ b/packages/flutter/test/widget/block_test.dart @@ -105,4 +105,18 @@ void main() { expect(first, equals(1)); expect(second, equals(1)); }); + + testWidgets('Block scrollableKey', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/4046 + // The Block's scrollableKey needs to become its Scrollable descendant's key. + final GlobalKey> key = new GlobalKey>(); + Widget buildBlock() { + return new Block( + scrollableKey: key, + children: [new Text("A"), new Text("B"), new Text("C")] + ); + } + await tester.pumpWidget(buildBlock()); + expect(key.currentState.scrollOffset, 0.0); + }); }