Removed Stepper accentColor dependency (#77732)
This commit is contained in:
@@ -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>[
|
||||
/// 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<Stepper> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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>[
|
||||
Step(
|
||||
title: const Text('step'),
|
||||
content: const Text('content'),
|
||||
isActive: isActive,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color? circleFillColor() {
|
||||
final Finder container = find.widgetWithText(AnimatedContainer, '1');
|
||||
return (tester.widget<AnimatedContainer>(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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user