forked from Tencent/tdesign-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtd_stepper_page.dart
More file actions
152 lines (138 loc) · 4.4 KB
/
td_stepper_page.dart
File metadata and controls
152 lines (138 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import '../annotation/demo.dart';
import '../base/example_widget.dart';
class TDStepperPage extends StatefulWidget {
const TDStepperPage({Key? key}) : super(key: key);
@override
State<TDStepperPage> createState() => _TDStepperPageState();
}
class _TDStepperPageState extends State<TDStepperPage> {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
var currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus &&
currentFocus.focusedChild != null) {
FocusManager.instance.primaryFocus!.unfocus();
}
},
child: ExamplePage(
title: tdTitle(),
desc: '用于数量的增减。',
exampleCodeGroup: 'stepper',
children: [
ExampleModule(title: '组件类型', children: [
ExampleItem(desc: '基础步进器', builder: _buildStepperWithBase),
]),
ExampleModule(title: '组件状态', children: [
ExampleItem(desc: '最大最小状态', builder: _buildStepperWithMaxMinStatus),
ExampleItem(desc: '禁用状态', builder: _buildStepperWithDisableStatus)
]),
ExampleModule(title: '组件样式', children: [
ExampleItem(desc: '步进器样式', builder: _buildStepperWithTheme),
ExampleItem(desc: '步进器尺寸', builder: _buildStepperWithSize)
]),
],
test: [
ExampleItem(desc: '自定义stepValue', builder: _customStepperValue),
],
),
);
}
@Demo(group: 'stepper')
Widget _buildStepperWithBase(BuildContext context) {
return _buildRow(context, [
const TDStepper(
theme: TDStepperTheme.filled,
)
]);
}
@Demo(group: 'stepper')
Widget _buildStepperWithMaxMinStatus(BuildContext context) {
return _buildRow(context, [
const TDStepper(theme: TDStepperTheme.filled, value: 0, min: 0),
const TDStepper(theme: TDStepperTheme.filled, value: 999, max: 999),
]);
}
@Demo(group: 'stepper')
Widget _buildStepperWithDisableStatus(BuildContext context) {
return _buildRow(context, [
const TDStepper(
theme: TDStepperTheme.filled,
disabled: true,
),
const TDStepper(
theme: TDStepperTheme.outline,
disabled: true,
),
const TDStepper(
theme: TDStepperTheme.normal,
disabled: true,
),
]);
}
@Demo(group: 'stepper')
Widget _buildStepperWithTheme(BuildContext context) {
return _buildRow(context, [
const TDStepper(theme: TDStepperTheme.filled, value: 3),
const TDStepper(theme: TDStepperTheme.outline, value: 3),
const TDStepper(theme: TDStepperTheme.normal, value: 3),
]);
}
@Demo(group: 'stepper')
Widget _buildStepperWithSize(BuildContext context) {
return _buildRow(context, [
const TDStepper(
size: TDStepperSize.large, theme: TDStepperTheme.filled, value: 3),
const TDStepper(
size: TDStepperSize.medium, theme: TDStepperTheme.filled, value: 3),
const TDStepper(
size: TDStepperSize.small, theme: TDStepperTheme.filled, value: 3),
]);
}
@Demo(group: 'stepper')
Widget _buildRow(BuildContext context, List<Widget> stepperItems) {
final theme = TDTheme.of(context);
return Container(
decoration: BoxDecoration(
color: theme.bgColorContainer,
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: stepperItems
.map((item) => SizedBox(
width: (MediaQuery.of(context).size.width - 32) / 3,
child: item,
))
.toList(),
),
),
);
}
var controller = TDStepperController()..value = 1;
@Demo(group: 'stepper')
Widget _customStepperValue(BuildContext context) {
return Container(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
TDStepper(
theme: TDStepperTheme.filled,
controller: controller,
),
TDButton(
text: 'value * 2',
onTap: () {
controller.value *= 2;
},
)
],
),
);
}
}