From dfce0a7f0be217c2f0fba49f16e26d6605665835 Mon Sep 17 00:00:00 2001 From: Jake Gough Date: Tue, 12 Feb 2019 22:02:36 +0000 Subject: [PATCH] Added 'physics' prop to Stepper. (#26297) * Update stepper.dart Added 'physics' prop which allows the developer to assign the Stepper's scroll view's 'ScrollPhysics' which can solve with unwanted scrolling behaviour if the parent is also a scroll view. Defaults to 'AlwaysScrollableScrollPhysics' if null. * Update stepper.dart Removed unnecessary import and defaulting to 'AlwaysScrollableScrollPhysics' if physics prop is null. * Update stepper.dart Ran through format to remove unwanted whitespace which Analysis isn't happy about. * Update stepper.dart Tried reformatting again. * Update stepper.dart Tried reformatting again. * Update stepper.dart Formatting again why do you hate me github editor. * Update stepper.dart * Update stepper.dart if this format doesn't work i'll cry * Update stepper_test.dart Added Stepper scroll tests. One that fails to find Text after Stepper if physics left as null and one that succeeds if physics set to `ClampingScrollPhysics()` * Update stepper_test.dart Added const constructors * Update stepper_test.dart trying to get rid of whitespace again * Update stepper_test.dart * Update stepper_test.dart why whitespace why * Update stepper_test.dart * Update stepper_test.dart * Update stepper_test.dart * Update stepper_test.dart Swapped to `findsNothing` because I'm an idiot. * Update stepper_test.dart * Update stepper.dart --- .../flutter/lib/src/material/stepper.dart | 11 +++++++ .../flutter/test/material/stepper_test.dart | 33 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index b0aab18929..29fa2422ea 100644 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -135,6 +135,7 @@ class Stepper extends StatefulWidget { Stepper({ Key key, @required this.steps, + this.physics, this.type = StepperType.vertical, this.currentStep = 0, this.onStepTapped, @@ -152,6 +153,15 @@ class Stepper extends StatefulWidget { /// The length of [steps] must not change. final List steps; + /// How the stepper's scroll view should respond to user input. + /// + /// For example, determines how the scroll view continues to + /// animate after the user stops dragging the scroll view. + /// + /// If the stepper is contained within another scrollable it + /// can be helpful to set this property to [ClampingScrollPhysics]. + final ScrollPhysics physics; + /// The type of stepper that determines the layout. In the case of /// [StepperType.horizontal], the content of the current step is displayed /// underneath as opposed to the [StepperType.vertical] case where it is @@ -594,6 +604,7 @@ class _StepperState extends State with TickerProviderStateMixin { return ListView( shrinkWrap: true, + physics: widget.physics, children: children, ); } diff --git a/packages/flutter/test/material/stepper_test.dart b/packages/flutter/test/material/stepper_test.dart index 24eeeea242..81e9ca7fc6 100644 --- a/packages/flutter/test/material/stepper_test.dart +++ b/packages/flutter/test/material/stepper_test.dart @@ -507,4 +507,37 @@ void main() { renderObject = tester.renderObject(find.byIcon(Icons.check)); expect(renderObject.size, equals(const Size.square(18.0))); }); + + testWidgets('Stepper physics scroll error test', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Material( + child: ListView( + children: [ + Stepper( + steps: const [ + Step(title: Text('Step 1'), content: Text('Text 1')), + Step(title: Text('Step 2'), content: Text('Text 2')), + Step(title: Text('Step 3'), content: Text('Text 3')), + Step(title: Text('Step 4'), content: Text('Text 4')), + Step(title: Text('Step 5'), content: Text('Text 5')), + Step(title: Text('Step 6'), content: Text('Text 6')), + Step(title: Text('Step 7'), content: Text('Text 7')), + Step(title: Text('Step 8'), content: Text('Text 8')), + Step(title: Text('Step 9'), content: Text('Text 9')), + Step(title: Text('Step 10'), content: Text('Text 10')), + ], + ), + const Text('Text After Stepper'), + ], + ), + ), + ), + ); + + await tester.fling(find.byType(Stepper), const Offset(0.0, -100.0), 1000.0); + await tester.pumpAndSettle(); + + expect(find.text('Text After Stepper'), findsNothing); + }); }