Skip to content

Commit 850b7ce

Browse files
samsam
authored andcommitted
feat: Stepper
1 parent c065333 commit 850b7ce

File tree

4 files changed

+124
-12
lines changed

4 files changed

+124
-12
lines changed
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
## **文档完善中**
1+
## **Stepper**
2+
3+
>
4+
一个步骤小控件,通过一系列步骤显示进度,对于表单的情况,Stepper特别有用,可以通过控制需要完成多个步骤才能提交的表单
5+
6+
### 构造方法
7+
``` dart
8+
Stepper({
9+
Key key,
10+
@required this.steps,
11+
this.physics,
12+
this.type = StepperType.vertical,
13+
this.currentStep = 0,
14+
this.onStepTapped,
15+
this.onStepContinue,
16+
this.onStepCancel,
17+
this.controlsBuilder,
18+
})
19+
```
20+
21+
### 属性介绍
22+
* steps: Stepper的内容,包含标题,副标题,内容
23+
* physics: Stepper滚动视图应如何响应用户输入
24+
* type = StepperType.vertical: 确定Stepper的布局类型
25+
* currentStep: 当前步骤索引,内容被显示
26+
* onStepTapped: step被点击时的回调
27+
* onStepContinue: 点击 继续 按钮时的回调
28+
* onStepCancel: 点击 取消 按钮时的回调
29+
* controlsBuilder: 用于创建自定义控件的回调

lib/components/widgetComp.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class IndexState extends State<Index> {
7979
this._bodyList.add(authorTile(nameKey));
8080
this._bodyList.add(Divider());
8181
}
82+
print('文档完成长度:${mdText.length}');
8283
if (mdText.length > 30) {
8384
this._bodyList.add(await MarkDownComp.Index(mdText));
8485
// demo

lib/widget/common/stepper/demo.dart

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ class Index extends StatefulWidget {
77

88
class _IndexState extends State<Index> {
99
int _currentStep = 0;
10+
// final _textEditingController1 = TextEditingController();
11+
// final _textEditingController2 = TextEditingController();
12+
// final _textEditingController3 = TextEditingController();
13+
List<TextEditingController> _textEditingController = [TextEditingController(), TextEditingController(), TextEditingController()];
14+
1015
@override
1116
void initState() {
1217
super.initState();
@@ -25,9 +30,11 @@ class _IndexState extends State<Index> {
2530
children: <Widget>[
2631
Theme(
2732
data: Theme.of(context).copyWith(
28-
primaryColor: Colors.black
33+
primaryColor: Theme.of(context).primaryColor
2934
),
3035
child: Stepper(
36+
physics: NeverScrollableScrollPhysics(),
37+
type: StepperType.vertical,
3138
currentStep: _currentStep,
3239
onStepTapped: (int value) {
3340
setState(() {
@@ -46,29 +53,105 @@ class _IndexState extends State<Index> {
4653
},
4754
steps: [
4855
Step(
49-
title: Text('Login'),
50-
subtitle: Text('Login first'),
51-
content: Text('Confirm your information'),
56+
title: Text('Name'),
57+
subtitle: Text('User name'),
58+
content: Container(
59+
padding: EdgeInsets.all(10.0),
60+
child: TextField(
61+
controller: _textEditingController[0],
62+
maxLength: 10,
63+
style: TextStyle(
64+
fontSize: 20.0,
65+
color: Theme.of(context).primaryColor
66+
),
67+
// autofocus: true,
68+
decoration: InputDecoration(
69+
icon: Icon(Icons.people),
70+
labelText: 'Name',
71+
border: OutlineInputBorder(
72+
borderRadius: BorderRadius.circular(15.0)
73+
)
74+
),
75+
),
76+
),
5277
isActive: _currentStep == 0
5378
),
5479
Step(
55-
title: Text('Choose plan'),
56-
subtitle: Text('Choose your plan'),
57-
content: Text('Confirm your information'),
80+
title: Text('Phone'),
81+
subtitle: Text('User phone'),
82+
content: Container(
83+
padding: EdgeInsets.all(10.0),
84+
child: TextField(
85+
controller: _textEditingController[1],
86+
maxLength: 18,
87+
style: TextStyle(
88+
fontSize: 20,
89+
color: Theme.of(context).primaryColor
90+
),
91+
keyboardType: TextInputType.phone,
92+
decoration: InputDecoration(
93+
icon: Icon(Icons.phone),
94+
labelText: 'Phone',
95+
border: OutlineInputBorder(
96+
borderRadius: BorderRadius.circular(15.0)
97+
)
98+
),
99+
),
100+
),
58101
isActive: _currentStep == 1
59102
),
60103
Step(
61-
title: Text('Confirm payment'),
62-
subtitle: Text('Confirm yoir payment method'),
63-
content: Text('Confirm your information'),
104+
title: Text('Email'),
105+
subtitle: Text('User email'),
106+
content: Container(
107+
padding: EdgeInsets.all(10.0),
108+
child: TextField(
109+
controller: _textEditingController[2],
110+
maxLength: 20,
111+
style: TextStyle(
112+
fontSize: 20,
113+
color: Theme.of(context).primaryColor
114+
),
115+
keyboardType: TextInputType.emailAddress,
116+
decoration: InputDecoration(
117+
icon: Icon(Icons.email),
118+
labelText: 'Email',
119+
border: OutlineInputBorder(
120+
borderRadius: BorderRadius.circular(15.0)
121+
)
122+
),
123+
),
124+
),
64125
isActive: _currentStep == 2
65126
),
66127
],
67128
),
129+
),
130+
RaisedButton(
131+
color: Theme.of(context).primaryColor,
132+
onPressed: _openSimpleDialog,
133+
child: Text('Click on me to show information',style: TextStyle(color: Colors.white),),
68134
)
69135
],
70136
),
71137
)
72138
);
73139
}
140+
141+
Future _openSimpleDialog () async {
142+
showDialog(
143+
context: context,
144+
builder: (BuildContext context) {
145+
return SimpleDialog(
146+
title: Text('User Information'),
147+
titlePadding: EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 0),
148+
contentPadding: EdgeInsets.fromLTRB(24.0, 12.0, 0.0, 16.0),
149+
children: List.generate(3, (index) {
150+
return Text('${_textEditingController[index].text}');
151+
}),
152+
);
153+
}
154+
);
155+
}
156+
74157
}

readme/widget_progress.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Flutter UI
6060
│ ├─placeholder
6161
│ ├─raisedbutton
6262
│ ├─rawimage
63-
│ ├─stepper
63+
│ ├─stepper 【✔️ v1.0】
6464
│ ├─text 【✔️ v1.0】
6565
│ └─tooltip
6666
├─form

0 commit comments

Comments
 (0)