瞎扯
新年上班第一天.
form表单
flutter不愧是个UI框架.
其实把它和ios android来比.是不能比的.
一个只是框架,ios和android是系统.还是不一样.
这点要想明白,
form这个概念,在安卓里面没有,在ios里应该也没有,在前端才有.
虽然android和ios都会写表单页面.但是没有一个专门的weight做这个事情
flutter不一样,专门提供了一个
weight
class Form extends StatefulWidget {
/// Creates a container for form fields.
///
/// The [child] argument must not be null.
const Form({
Key key,
@required this.child,
this.autovalidate = false,
this.onWillPop,
this.onChanged,
}) : assert(child != null),
super(key: key);
state
class FormState extends State<Form> {
int _generation = 0;
final Set<FormFieldState<dynamic>> _fields = Set<FormFieldState<dynamic>>();
// Called when a form field has changed. This will cause all form fields
// to rebuild, useful if form fields have interdependencies.
void _fieldDidChange() {
if (widget.onChanged != null)
widget.onChanged();
_forceRebuild();
}
和前端十分类似.大致就是监听form下的每一个被TextFormField
,FormField
.包装的child.
也就是FormState
的会add,每一个被FormField
包装的weight.然后统一控制.
class FormField<T> extends StatefulWidget {
/// Creates a single form field.
///
/// The [builder] argument must not be null.
const FormField({
Key key,
@required this.builder,
this.onSaved, //保存规则
this.validator, //校验规则
this.initialValue, //初始化的值
this.autovalidate = false, //自动校验
this.enabled = true,
}) : assert(builder != null),
super(key: key);
这些其实和react很像,双向绑定,
总结:
form常用的方法.比如: reset 重置表单内容 , save 表单保存, validate触发校验.
FormField几乎每个方法都常用.
交流群:493180098,这是个很少吹水,交流学习的群.
APP开发维护咨询群 : 492685472 ,承接APP迭代.开发维护.咨询业务,付费快速解决问题.