diff --git a/packages/flutter/lib/src/material/stepper.dart b/packages/flutter/lib/src/material/stepper.dart index 9881fcf49f..b15581e509 100755 --- a/packages/flutter/lib/src/material/stepper.dart +++ b/packages/flutter/lib/src/material/stepper.dart @@ -127,46 +127,32 @@ class Step { /// ```dart /// int _index = 0; /// Widget build(BuildContext context) { -/// return Container( -/// height: 300, -/// width: 300, -/// child: Stepper( -/// currentStep: _index, -/// onStepCancel: () { -/// if (_index <= 0) { -/// return; -/// } -/// setState(() { -/// _index--; -/// }); -/// }, -/// onStepContinue: () { -/// if (_index >= 1) { -/// return; -/// } -/// setState(() { -/// _index++; -/// }); -/// }, -/// onStepTapped: (index) { -/// setState(() { -/// _index = index; -/// }); -/// }, -/// steps: [ -/// Step( -/// title: Text("Step 1 title"), -/// content: Container( -/// alignment: Alignment.centerLeft, -/// child: Text("Content for Step 1") -/// ), +/// return Stepper( +/// currentStep: _index, +/// onStepCancel: () { +/// if (_index > 0) +/// setState(() { _index -= 1; }); +/// }, +/// onStepContinue: () { +/// if (_index <= 0) +/// setState(() { _index += 1; }); +/// }, +/// onStepTapped: (index) { +/// setState(() { _index = index; }); +/// }, +/// steps: [ +/// Step( +/// title: Text('Step 1 title'), +/// content: Container( +/// alignment: Alignment.centerLeft, +/// child: Text('Content for Step 1') /// ), -/// Step( -/// title: Text("Step 2 title"), -/// content: Text("Content for Step 2"), -/// ), -/// ], -/// ), +/// ), +/// Step( +/// title: Text('Step 2 title'), +/// content: Text('Content for Step 2'), +/// ), +/// ], /// ); /// } /// ``` @@ -372,11 +358,11 @@ class _StepperState extends State with TickerProviderStateMixin { } Color _circleColor(int index) { - final ThemeData themeData = Theme.of(context); + final ColorScheme colorScheme = Theme.of(context).colorScheme; if (!_isDark()) { - return widget.steps[index].isActive ? themeData.primaryColor : Colors.black38; + return widget.steps[index].isActive ? colorScheme.primary : colorScheme.onSurface.withOpacity(0.38); } else { - return widget.steps[index].isActive ? themeData.accentColor : themeData.backgroundColor; + return widget.steps[index].isActive ? colorScheme.secondary : colorScheme.background; } } diff --git a/packages/flutter/test/material/stepper_test.dart b/packages/flutter/test/material/stepper_test.dart index 0fee96921d..115f5e4cb0 100644 --- a/packages/flutter/test/material/stepper_test.dart +++ b/packages/flutter/test/material/stepper_test.dart @@ -842,4 +842,49 @@ void main() { expect(listView.physics, physics); } }); + + 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 }) { + return MaterialApp( + theme: brightness == Brightness.dark ? ThemeData.dark() : ThemeData.light(), + home: Scaffold( + body: Center( + child: Stepper( + type: StepperType.horizontal, + steps: [ + Step( + title: const Text('step'), + content: const Text('content'), + isActive: isActive, + ), + ], + ), + ), + ), + ); + } + + Color? circleFillColor() { + final Finder container = find.widgetWithText(AnimatedContainer, '1'); + return (tester.widget(container).decoration as BoxDecoration?)?.color; + } + + // Light theme + final ColorScheme light = ThemeData.light().colorScheme; + await tester.pumpWidget(buildFrame(isActive: true, brightness: Brightness.light)); + expect(circleFillColor(), light.primary); + await tester.pumpWidget(buildFrame(isActive: false, brightness: Brightness.light)); + await tester.pumpAndSettle(); + expect(circleFillColor(), light.onSurface.withOpacity(0.38)); + + // Dark theme + final ColorScheme dark = ThemeData.dark().colorScheme; + await tester.pumpWidget(buildFrame(isActive: true, brightness: Brightness.dark)); + await tester.pumpAndSettle(); + expect(circleFillColor(), dark.secondary); + await tester.pumpWidget(buildFrame(isActive: false, brightness: Brightness.dark)); + await tester.pumpAndSettle(); + expect(circleFillColor(), dark.background); + }); }