From 5e19b33534bcdf08e04abac15af3d7c7759b4df2 Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Mon, 25 Mar 2024 23:47:05 +0200 Subject: [PATCH] Fix vertical `Stepper` draws connector on the last step (#145703) fixes [Vertical stepper shows line after last step](https://github.com/flutter/flutter/issues/144376) ### Code sample
expand to view the code sample ```dart import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Scaffold( body: Center( child: Stepper( currentStep: 1, steps: const [ Step( title: Text("Step 1"), content: Text("Content 1"), ), Step( title: Text("Step 2"), content: Text("Content 2"), ), ], ), ), ), ); } } ```
### Before ![Screenshot 2024-03-25 at 18 36 32](https://github.com/flutter/flutter/assets/48603081/af859a88-7ec8-4432-8eec-f8eb72706b57) ### After ![Screenshot 2024-03-25 at 18 36 24](https://github.com/flutter/flutter/assets/48603081/994325b2-4bd4-44ef-9473-245d3492faf7) --- .../flutter/lib/src/material/stepper.dart | 2 +- .../flutter/test/material/stepper_test.dart | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index e1071a1a986..4b3f3a604e1 100644 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -791,7 +791,7 @@ class _StepperState extends State with TickerProviderStateMixin { width: _stepIconWidth ?? _kStepSize, child: Center( child: SizedBox( - width: widget.connectorThickness ?? 1.0, + width: !_isLast(index) ? (widget.connectorThickness ?? 1.0) : 0.0, child: Container( color: _connectorColor(widget.steps[index].isActive), ), diff --git a/packages/flutter/test/material/stepper_test.dart b/packages/flutter/test/material/stepper_test.dart index e21bc6fb4cd..5b2349e082a 100644 --- a/packages/flutter/test/material/stepper_test.dart +++ b/packages/flutter/test/material/stepper_test.dart @@ -1689,6 +1689,37 @@ testWidgets('Stepper custom indexed controls test', (WidgetTester tester) async expect(mergedStyle.gradient, stepStyle.gradient); expect(mergedStyle.indexStyle, stepStyle.indexStyle); }); + + // This is a regression test for https://github.com/flutter/flutter/issues/144376. + testWidgets('Vertical Stepper does not draw connector on the last step', (WidgetTester tester) async { + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: Center( + child: Stepper( + currentStep: 1, + steps: const [ + Step( + title: Text('step1'), + content: Text('step1 content'), + ), + Step( + title: Text('step2'), + content: Text('step2 content'), + ), + ], + ), + ), + ), + ) + ); + + final SizedBox lastConnector = tester.widget( + find.descendant(of: find.byType(PositionedDirectional), + matching: find.byType(SizedBox).last, + )); + expect(lastConnector.width, equals(0.0)); + }); } class _TappableColorWidget extends StatefulWidget {