Skip to content

Commit 57db272

Browse files
committed
TextField
1 parent 85b0201 commit 57db272

File tree

3 files changed

+143
-27
lines changed

3 files changed

+143
-27
lines changed
Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,64 @@
1-
## **文档完善中**
1+
## **TextField**
2+
3+
>
4+
TextField最常用的文本输入Widget
5+
6+
7+
### 构造方法
8+
``` dart
9+
TextField({
10+
Key key,
11+
this.controller,
12+
this.focusNode,
13+
this.decoration = const InputDecoration(),
14+
TextInputType keyboardType,
15+
this.textInputAction,
16+
this.textCapitalization = TextCapitalization.none,
17+
this.style,
18+
this.strutStyle,
19+
this.textAlign = TextAlign.start,
20+
this.textDirection,
21+
this.autofocus = false,
22+
this.obscureText = false,
23+
this.autocorrect = true,
24+
this.maxLines = 1,
25+
this.maxLength,
26+
this.maxLengthEnforced = true,
27+
this.onChanged,
28+
this.onEditingComplete,
29+
this.onSubmitted,
30+
this.inputFormatters,
31+
this.enabled,
32+
this.cursorWidth = 2.0,
33+
this.cursorRadius,
34+
this.cursorColor,
35+
this.keyboardAppearance,
36+
this.scrollPadding = const EdgeInsets.all(20.0),
37+
this.dragStartBehavior = DragStartBehavior.start,
38+
this.enableInteractiveSelection,
39+
this.onTap,
40+
this.buildCounter,
41+
})
42+
```
43+
44+
### 属性介绍
45+
* controller:TextField的控制器,可用来添加通知或者获取TextField的值,如controller.text
46+
* decoration = const InputDecoration():装饰器,设置相关的属性能构造出各种TextField效果,详情见Demo
47+
* TextInputType keyboardType:TextField获得焦点时弹出的键盘类型
48+
* style:输入框文本样式
49+
* textAlign:文本对齐方式
50+
* textDirection:文本方向
51+
* autofocus:是否自动对焦
52+
* obscureText:是否以密码形式显示
53+
* autocorrect:是否自动更正
54+
* maxLines:最大行数
55+
* maxLength:最大长度,设置此项会让TextField右下角有一个输入数量的统计字符串
56+
* maxLengthEnforced = true:
57+
* onChanged:输入框内容改变进行回调
58+
* onEditingComplete:输入完毕回调
59+
* onSubmitted:内容提交,回车的回调
60+
* enabled:是否禁用
61+
* cursorWidth = 2.0:光标的宽度
62+
* cursorRadius:光标的角的圆角
63+
* cursorColor:光标的颜色
64+
* onTap:点击文本时调用

lib/widget/form/textfield/demo.dart

Lines changed: 78 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,87 @@ class _IndexState extends State<Index> {
2929
appBar: AppBar(
3030
title: Text('TextField'),
3131
),
32-
body: Center(
33-
child: Container(
34-
padding: EdgeInsets.all(10.0),
35-
child: TextField(
36-
controller: _textEditingController,
37-
maxLength: 20,
38-
maxLines: 1,
39-
obscureText: false,
40-
textAlign: TextAlign.center,
41-
style: TextStyle(
42-
fontSize: 20.0,
43-
color: Theme.of(context).primaryColor
32+
body: ListView(
33+
children: <Widget>[
34+
Container(
35+
padding: EdgeInsets.all(10.0),
36+
child: TextField(
37+
controller: _textEditingController,
38+
maxLength: 20,
39+
maxLines: 1,
40+
obscureText: false,
41+
textAlign: TextAlign.start,
42+
style: TextStyle(
43+
fontSize: 20.0,
44+
color: Theme.of(context).primaryColor
45+
),
46+
onChanged: (value) {
47+
print('正在输入:$value');
48+
},
49+
onSubmitted: (value) {
50+
print('sumbit输入完毕: $value');
51+
},
52+
decoration: InputDecoration(
53+
icon: Icon(Icons.subject),
54+
labelText: 'Title',
55+
hintText: 'Enter the post title',
56+
errorText: 'error',
57+
),
4458
),
45-
onChanged: (value) {
46-
print('正在输入:$value');
47-
},
48-
onSubmitted: (value) {
49-
print('sumbit输入完毕: $value');
50-
},
51-
decoration: InputDecoration(
52-
icon: Icon(Icons.subject),
53-
// labelText: 'Title',
54-
// hintText: 'Enter the post title',
55-
// filled: true
59+
),
60+
Container(
61+
padding: EdgeInsets.all(10.0),
62+
child: TextField(
63+
controller: _textEditingController,
64+
maxLength: 20,
65+
maxLines: 1,
66+
obscureText: false,
67+
textAlign: TextAlign.start,
68+
style: TextStyle(
69+
fontSize: 20.0,
70+
color: Theme.of(context).primaryColor
71+
),
72+
keyboardType: TextInputType.phone,
73+
decoration: InputDecoration(
74+
labelText: 'Title',
75+
hintText: 'Enter the post title',
76+
helperText: 'phone',
77+
filled: true,
78+
fillColor: Colors.blue.shade100,
79+
prefixIcon: Icon(Icons.local_airport),
80+
suffixText: 'airport'
81+
),
5682
),
5783
),
58-
)
59-
),
84+
Container(
85+
padding: EdgeInsets.all(10.0),
86+
child: TextField(
87+
controller: _textEditingController,
88+
maxLength: 20,
89+
style: TextStyle(
90+
fontSize: 20.0,
91+
color: Theme.of(context).primaryColor
92+
),
93+
keyboardType: TextInputType.number,
94+
cursorColor: Colors.green,
95+
// cursorRadius: Radius.circular(20),
96+
// cursorWidth: 40,
97+
decoration: InputDecoration(
98+
labelText: 'Title',
99+
hintText: 'Enter the post title',
100+
helperText: 'number',
101+
filled: true,
102+
fillColor: Colors.blue.shade100,
103+
prefixIcon: Icon(Icons.local_airport),
104+
suffixIcon: Icon(Icons.local_drink),
105+
border: OutlineInputBorder(
106+
borderRadius: BorderRadius.circular(15.0)
107+
)
108+
),
109+
),
110+
)
111+
],
112+
)
60113
);
61114
}
62115
}

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Flutter UI
134134
│ ├─form
135135
│ ├─formfield
136136
│ ├─rawkeyboard
137-
│ ├─textfield
137+
│ ├─textfield 【✔️ v1.0】
138138
│ └─textinput
139139
├─gestures
140140
│ ├─absorbpointer

0 commit comments

Comments
 (0)