diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index 3d374ddf3e..b6ab24a64a 100644 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -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 with TickerProviderStateMixin { Widget _buildVertical() { return ListView( + controller: widget.controller, shrinkWrap: true, physics: widget.physics, children: [ @@ -858,6 +867,7 @@ class _StepperState extends State with TickerProviderStateMixin { ), Expanded( child: ListView( + controller: widget.controller, physics: widget.physics, padding: const EdgeInsets.all(24.0), children: [ diff --git a/packages/flutter/test/material/stepper_test.dart b/packages/flutter/test/material/stepper_test.dart index 3ed4bf59e4..d85070b607 100644 --- a/packages/flutter/test/material/stepper_test.dart +++ b/packages/flutter/test/material/stepper_test.dart @@ -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( + title: Text('Step 1'), + content: SizedBox( + width: 100.0, + height: 100.0, + ), + ), + ], + ), + ), + ), + ); + + final ListView listView = tester.widget( + 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 }) {