Form表单需要设置一个全局类型的GlobalKey,通过这个key获取表单对象
GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
//获取表单当前实例对象
_formKey.currentState;
//重置表单内容
_formKey.currentState.reset();
//验证表单内容,表单里面TextFiled等组件验证通过后才到达此步
_formKey.currentState.validate();
//保存表单内容
_formKey.currentState.save();
常用表单组件:
输入框(TextField)和表单输入框(TextFormField)
TextField:
const TextField({
Key key,
this.controller,
this.focusNode,
this.decoration = const InputDecoration(),
TextInputType keyboardType,
this.textInputAction,
this.textCapitalization = TextCapitalization.none,
this.style,
this.strutStyle,
this.textAlign = TextAlign.start,
this.textAlignVertical,
this.textDirection,
this.readOnly = false,
ToolbarOptions toolbarOptions,
this.showCursor,
this.autofocus = false,
this.obscureText = false,
this.autocorrect = true,
this.maxLines = 1,
this.minLines,
this.expands = false,
this.maxLength,
this.maxLengthEnforced = true,
this.onChanged,
this.onEditingComplete,
this.onSubmitted,
this.inputFormatters,
this.enabled,
this.cursorWidth = 2.0,
this.cursorRadius,
this.cursorColor,
this.keyboardAppearance,
this.scrollPadding = const EdgeInsets.all(