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
This commit is contained in:
@@ -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<Step> 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<Stepper> with TickerProviderStateMixin {
|
||||
|
||||
return ListView(
|
||||
shrinkWrap: true,
|
||||
physics: widget.physics,
|
||||
children: children,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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: <Widget>[
|
||||
Stepper(
|
||||
steps: const <Step>[
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user