From 6491cbf7a3739326262e0294829bf93d29d63e21 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 27 Feb 2017 17:17:29 -0800 Subject: [PATCH] Ensure PrimaryScrollController is returned when primary: true (#8440) Also a small formatting fix. --- .../flutter/lib/src/widgets/scroll_view.dart | 3 +- .../test/widgets/scroll_view_test.dart | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/widgets/scroll_view.dart b/packages/flutter/lib/src/widgets/scroll_view.dart index b1b719727d..06c85184f5 100644 --- a/packages/flutter/lib/src/widgets/scroll_view.dart +++ b/packages/flutter/lib/src/widgets/scroll_view.dart @@ -30,7 +30,8 @@ abstract class ScrollView extends StatelessWidget { assert(primary != null); assert(controller == null || !primary, 'Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. ' - 'You cannot both set primary to true and pass an explicit controller.'); + 'You cannot both set primary to true and pass an explicit controller.' + ); } final Axis scrollDirection; diff --git a/packages/flutter/test/widgets/scroll_view_test.dart b/packages/flutter/test/widgets/scroll_view_test.dart index c44b90de71..fefda98ae7 100644 --- a/packages/flutter/test/widgets/scroll_view_test.dart +++ b/packages/flutter/test/widgets/scroll_view_test.dart @@ -168,4 +168,34 @@ void main() { expect(controller.offset, equals(550.0)); expect(log, isEmpty); }); + + testWidgets('CustomScrollView sets PrimaryScrollController when primary', (WidgetTester tester) async { + ScrollController primaryScrollController = new ScrollController(); + await tester.pumpWidget(new PrimaryScrollController( + controller: primaryScrollController, + child: new CustomScrollView(primary: true), + )); + Scrollable scrollable = tester.widget(find.byType(Scrollable)); + expect(scrollable.controller, primaryScrollController); + }); + + testWidgets('ListView sets PrimaryScrollController when primary', (WidgetTester tester) async { + ScrollController primaryScrollController = new ScrollController(); + await tester.pumpWidget(new PrimaryScrollController( + controller: primaryScrollController, + child: new ListView(primary: true), + )); + Scrollable scrollable = tester.widget(find.byType(Scrollable)); + expect(scrollable.controller, primaryScrollController); + }); + + testWidgets('GridView sets PrimaryScrollController when primary', (WidgetTester tester) async { + ScrollController primaryScrollController = new ScrollController(); + await tester.pumpWidget(new PrimaryScrollController( + controller: primaryScrollController, + child: new GridView.count(primary: true, crossAxisCount: 1), + )); + Scrollable scrollable = tester.widget(find.byType(Scrollable)); + expect(scrollable.controller, primaryScrollController); + }); }