Unverified Commit 80935ad9 authored by Swaroop S's avatar Swaroop S Committed by GitHub

Adding ScrollController support for Stepper widget (#128814)

This PR is to add **controller** property to the **Stepper** widget, so
that user has the flexibility to control the scroll offset for various
purposes(especially in case of scroll animations)!

Fixes #61207 
Co-authored-by: 's avatarTaha Tesser <tessertaha@gmail.com>
parent ca6f08a3
......@@ -202,6 +202,7 @@ class Stepper extends StatefulWidget {
const Stepper({
super.key,
required this.steps,
this.controller,
this.physics,
this.type = StepperType.vertical,
this.currentStep = 0,
......@@ -230,6 +231,13 @@ class Stepper extends StatefulWidget {
/// can be helpful to set this property to [ClampingScrollPhysics].
final ScrollPhysics? physics;
/// An object that can be used to control the position to which this scroll
/// view is scrolled.
///
/// To control the initial scroll offset of the scroll view, provide a
/// [controller] with its [ScrollController.initialScrollOffset] property set.
final ScrollController? controller;
/// 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
......@@ -765,6 +773,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
Widget _buildVertical() {
return ListView(
controller: widget.controller,
shrinkWrap: true,
physics: widget.physics,
children: <Widget>[
......@@ -858,6 +867,7 @@ class _StepperState extends State<Stepper> with TickerProviderStateMixin {
),
Expanded(
child: ListView(
controller: widget.controller,
physics: widget.physics,
padding: const EdgeInsets.all(24.0),
children: <Widget>[
......
......@@ -972,6 +972,37 @@ testWidgets('Stepper custom indexed controls test', (WidgetTester tester) async
}
});
testWidgets('ScrollController is passed to the stepper listview', (WidgetTester tester) async {
final ScrollController controller = ScrollController();
for (final StepperType type in StepperType.values) {
await tester.pumpWidget(
MaterialApp(
home: Material(
child: Stepper(
controller: controller,
type: type,
steps: const <Step>[
Step(
title: Text('Step 1'),
content: SizedBox(
width: 100.0,
height: 100.0,
),
),
],
),
),
),
);
final ListView listView = tester.widget<ListView>(
find.descendant(of: find.byType(Stepper),
matching: find.byType(ListView),
));
expect(listView.controller, controller);
}
});
testWidgets('Stepper horizontal size test', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/pull/77732
Widget buildFrame({ bool isActive = true, Brightness? brightness }) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment