Flutter学习笔记 Form表单

本文是Flutter学习笔记,重点介绍Form表单的使用,包括GlobalKey的设置,以及TextField、TextFormField、CheckBox、RadioButton、Slider、Switch等常见表单组件的运用,同时涵盖不同类型的按钮如FlatButton、IconButton等。
摘要由CSDN通过智能技术生成

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(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值