/**
* 大部分屬性同TextFiled
*
* TextFormField({
Key key,
this.controller,//控制正在編輯的文本。如果為空,這個小部件將創(chuàng)建自己的TextEditingController并使用initialValue初始化它的TextEditingController.text
String initialValue,//初始值
FocusNode focusNode,
InputDecoration decoration = const InputDecoration(),//輸入器裝飾
TextInputType keyboardType,//彈出鍵盤的類型
TextCapitalization textCapitalization = TextCapitalization.none,//戶輸入中的字母大寫的選項,TextCapitalization.sentences每個句子的首字母大寫,TextCapitalization.characters:句子中的所有字符都大寫篷就,TextCapitalization.words : 將每個單詞的首字母大寫。
TextInputAction textInputAction,//更改TextField的textInputAction可以更改鍵盤右下角的操作按鈕,搜索虫腋,完成
TextStyle style,
TextDirection textDirection,//文字顯示方向
TextAlign textAlign = TextAlign.start,//文字顯示位置
bool autofocus = false,//自動獲取焦點
bool obscureText = false,//是否隱藏輸入,true密碼樣式顯示稀余,false明文顯示
bool autocorrect = true,
bool autovalidate = false,//是否自動驗證值
bool maxLengthEnforced = true,
int maxLines = 1,//編輯框最多顯示行數(shù)
int maxLength,//輸入最大長度悦冀,并且默認(rèn)情況下會將計數(shù)器添加到TextField
VoidCallback onEditingComplete,//當(dāng)用戶提交時調(diào)用
ValueChanged<String> onFieldSubmitted,
FormFieldSetter<String> onSaved,//當(dāng)Form表單調(diào)用保存方法save時回調(diào)
FormFieldValidator<String> validator,//Form表單驗證
List<TextInputFormatter> inputFormatters,
bool enabled = true,
Brightness keyboardAppearance,
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
bool enableInteractiveSelection = true,
})
*/
body: Container(
padding: EdgeInsets.all(12.0),
color: Color(0xfff1f1f1),
child: Form(
key: _globalKey,
child: Column(
children: <Widget>[
TextFormField(
decoration: InputDecoration(
labelText: "請輸入用戶名",
labelStyle: TextStyle(
color: Colors.green,
fontSize: 20.0
)
),
onSaved: (value) { //formState.save()方法執(zhí)行完之后執(zhí)行onSaved方法
print("!!!!!!!!!!!!!!!! onSaved");
name = value;
},
onFieldSubmitted: (value) {
print("!!!!!!!!!!!!!!!! onFieldSubmitted:$value");
},
onEditingComplete: () {
print("!!!!!!!!!!!!!!!! onEditingComplete");
},
),
TextFormField(
decoration: InputDecoration(
labelText: "請輸入密碼"
),
onSaved: (value) {
passWord = value;
},
obscureText: true,
autovalidate: true,
validator: (value) {
return value.length < 4 ? "密碼長度不夠4位" : null;
},
),
Container(
margin: EdgeInsets.only(top: 20.0),
width: 200,
height: 40,
child: RaisedButton(
onPressed: dologin,
child: Text("登錄"),
),
)
],
),
),
),
/**
* 表單
*
* const Form({
Key key,
@required this.child,
this.autovalidate = false,//是否自動提交表單
this.onWillPop,
this.onChanged,//當(dāng)FormFiled值改變時的回調(diào)函數(shù)
})
*/
碼云地址:https://gitee.com/xgljh/Flutter.git