Skip to content

Commit f40a99c

Browse files
authored
Adds support for StepStyle visual property bundle to the Step widget (#140825)
Fixes #140770 and #103124 Adds the possibility of passing a height and width to icons. And also a margin for the distance of the lines between the icons.
1 parent ec97b6d commit f40a99c

File tree

4 files changed

+534
-23
lines changed

4 files changed

+534
-23
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
7+
/// Flutter code sample for [StepStyle].
8+
9+
void main() => runApp(const StepStyleExampleApp());
10+
11+
class StepStyleExampleApp extends StatelessWidget {
12+
13+
const StepStyleExampleApp({ super.key });
14+
15+
@override
16+
Widget build(BuildContext context) {
17+
return MaterialApp(
18+
home: Scaffold(
19+
appBar: AppBar(title: const Text('Step Style Example')),
20+
body: const Center(
21+
child: StepStyleExample(),
22+
),
23+
),
24+
);
25+
}
26+
}
27+
28+
class StepStyleExample extends StatefulWidget {
29+
const StepStyleExample({ super.key });
30+
31+
@override
32+
State<StepStyleExample> createState() => _StepStyleExampleState();
33+
}
34+
35+
class _StepStyleExampleState extends State<StepStyleExample> {
36+
final StepStyle _stepStyle = StepStyle(
37+
connectorThickness: 10,
38+
color: Colors.white,
39+
connectorColor: Colors.red,
40+
indexStyle: const TextStyle(
41+
color: Colors.black,
42+
fontSize: 20,
43+
),
44+
border: Border.all(
45+
width: 2,
46+
),
47+
);
48+
49+
@override
50+
Widget build(BuildContext context) {
51+
return Stepper(
52+
type: StepperType.horizontal,
53+
stepIconHeight: 48,
54+
stepIconWidth: 48,
55+
stepIconMargin: EdgeInsets.zero,
56+
steps: <Step>[
57+
Step(
58+
title: const SizedBox.shrink(),
59+
content: const SizedBox.shrink(),
60+
isActive: true,
61+
stepStyle: _stepStyle,
62+
),
63+
Step(
64+
title: const SizedBox.shrink(),
65+
content: const SizedBox.shrink(),
66+
isActive: true,
67+
stepStyle: _stepStyle.copyWith(
68+
connectorColor: Colors.orange,
69+
gradient: const LinearGradient(
70+
colors: <Color>[
71+
Colors.white,
72+
Colors.black,
73+
],
74+
),
75+
),
76+
),
77+
Step(
78+
title: const SizedBox.shrink(),
79+
content: const SizedBox.shrink(),
80+
isActive: true,
81+
stepStyle: _stepStyle.copyWith(
82+
connectorColor: Colors.blue,
83+
),
84+
),
85+
Step(
86+
title: const SizedBox.shrink(),
87+
content: const SizedBox.shrink(),
88+
isActive: true,
89+
stepStyle: _stepStyle.merge(
90+
StepStyle(
91+
color: Colors.white,
92+
indexStyle: const TextStyle(
93+
color: Colors.black,
94+
fontSize: 20,
95+
),
96+
border: Border.all(
97+
width: 2,
98+
),
99+
),
100+
),
101+
),
102+
],
103+
);
104+
}
105+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_api_samples/material/stepper/step_style.0.dart' as example;
7+
import 'package:flutter_test/flutter_test.dart';
8+
9+
void main() {
10+
testWidgets('StepStyle Smoke Test', (WidgetTester tester) async {
11+
await tester.pumpWidget(
12+
const example.StepStyleExampleApp(),
13+
);
14+
15+
expect(find.widgetWithText(AppBar, 'Step Style Example'), findsOneWidget);
16+
17+
final Stepper stepper = tester.widget<Stepper>(find.byType(Stepper));
18+
// Check that the stepper has the correct properties.
19+
expect(stepper.type, StepperType.horizontal);
20+
expect(stepper.stepIconHeight, 48);
21+
expect(stepper.stepIconWidth, 48);
22+
expect(stepper.stepIconMargin, EdgeInsets.zero);
23+
24+
// Check that the first step has the correct properties.
25+
final Step firstStep = stepper.steps[0];
26+
expect(firstStep.title, isA<SizedBox>());
27+
expect(firstStep.content, isA<SizedBox>());
28+
expect(firstStep.isActive, true);
29+
expect(firstStep.stepStyle?.connectorThickness, 10);
30+
expect(firstStep.stepStyle?.color, Colors.white);
31+
expect(firstStep.stepStyle?.connectorColor, Colors.red);
32+
expect(firstStep.stepStyle?.indexStyle?.color, Colors.black);
33+
expect(firstStep.stepStyle?.indexStyle?.fontSize, 20);
34+
expect(firstStep.stepStyle?.border, Border.all(width: 2));
35+
36+
// Check that the second step has the correct properties.
37+
final Step secondStep = stepper.steps[1];
38+
expect(secondStep.title, isA<SizedBox>());
39+
expect(secondStep.content, isA<SizedBox>());
40+
expect(secondStep.isActive, true);
41+
expect(secondStep.stepStyle?.connectorThickness, 10);
42+
expect(secondStep.stepStyle?.connectorColor, Colors.orange);
43+
expect(secondStep.stepStyle?.gradient, const LinearGradient(
44+
colors: <Color>[
45+
Colors.white,
46+
Colors.black,
47+
],
48+
));
49+
50+
// Check that the third step has the correct properties.
51+
final Step thirdStep = stepper.steps[2];
52+
expect(thirdStep.title, isA<SizedBox>());
53+
expect(thirdStep.content, isA<SizedBox>());
54+
expect(thirdStep.isActive, true);
55+
expect(thirdStep.stepStyle?.connectorThickness, 10);
56+
expect(thirdStep.stepStyle?.color, Colors.white);
57+
expect(thirdStep.stepStyle?.connectorColor, Colors.blue);
58+
expect(thirdStep.stepStyle?.indexStyle?.color, Colors.black);
59+
expect(thirdStep.stepStyle?.indexStyle?.fontSize, 20);
60+
expect(thirdStep.stepStyle?.border, Border.all(width: 2));
61+
62+
// Check that the fourth step has the correct properties.
63+
final Step fourthStep = stepper.steps[3];
64+
expect(fourthStep.title, isA<SizedBox>());
65+
expect(fourthStep.content, isA<SizedBox>());
66+
expect(fourthStep.isActive, true);
67+
expect(fourthStep.stepStyle?.color, Colors.white);
68+
expect(fourthStep.stepStyle?.indexStyle?.color, Colors.black);
69+
expect(fourthStep.stepStyle?.indexStyle?.fontSize, 20);
70+
expect(fourthStep.stepStyle?.border, Border.all(width: 2));
71+
});
72+
}

0 commit comments

Comments
 (0)