浏览代码

Fix form.

/main
Yuncong Zhang 6 年前
当前提交
eed13009
共有 3 个文件被更改,包括 43 次插入35 次删除
  1. 14
      Runtime/material/dropdown.cs
  2. 12
      Runtime/material/text_form_field.cs
  3. 52
      Runtime/widgets/form.cs

14
Runtime/material/dropdown.cs


}
}
public class DropdownButtonFormField<T> : FormField where T : class {
public class DropdownButtonFormField<T> : FormField<T> where T : class {
public DropdownButtonFormField(
Key key = null,
T value = null,

FormFieldSetter onSaved = null,
FormFieldValidator validator = null,
FormFieldSetter<T> onSaved = null,
FormFieldValidator<T> validator = null,
Widget hint = null
) : base(
key: key,

builder: (FormFieldState field) => {
builder: (FormFieldState<T> field) => {
InputDecoration effectiveDecoration = (decoration ?? new InputDecoration())
.applyDefaults(Theme.of(field.context).inputDecorationTheme);
return new InputDecorator(

}
}
class _DropdownButtonFormFieldState<T> : FormFieldState where T : class {
class _DropdownButtonFormFieldState<T> : FormFieldState<T> where T : class {
public override void didChange(object value) {
public override void didChange(T value) {
this.widget.onChanged((T) value);
this.widget.onChanged(value);
}
}
}

12
Runtime/material/text_form_field.cs


using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgets.Runtime.material {
public class TextFormField : FormField {
public class TextFormField : FormField<string> {
public TextFormField(
Key key = null,
TextEditingController controller = null,

int? maxLength = null,
VoidCallback onEditingComplete = null,
ValueChanged<string> onFieldSubmitted = null,
FormFieldSetter onSaved = null,
FormFieldValidator validator = null,
FormFieldSetter<string> onSaved = null,
FormFieldValidator<string> validator = null,
List<TextInputFormatter> inputFormatters = null,
bool enabled = true,
float cursorWidth = 2.0f,

validator: validator,
autovalidate: autovalidate,
enabled: enabled,
builder: (FormFieldState field) => {
builder: (FormFieldState<string> field) => {
_TextFormFieldState state = (_TextFormFieldState) field;
InputDecoration effectiveDecoration = (decoration ?? new InputDecoration())
.applyDefaults(Theme.of(field.context).inputDecorationTheme);

}
}
class _TextFormFieldState : FormFieldState {
class _TextFormFieldState : FormFieldState<string> {
TextEditingController _controller;
public TextEditingController _effectiveController {

public override void initState() {
base.initState();
if (this.widget.controller == null) {
this._controller = new TextEditingController(text: (string) this.widget.initialValue);
this._controller = new TextEditingController(text: this.widget.initialValue);
}
else {
this.widget.controller.addListener(this._handleControllerChanged);

52
Runtime/widgets/form.cs


public class FormState : State<Form> {
int _generation = 0;
public readonly HashSet<object> _fields = new HashSet<object>();
readonly HashSet<FormFieldState> _fields = new HashSet<FormFieldState>();
public FormState() {
}

this.setState(() => { ++this._generation; });
}
public void _register(object field) {
public void _register(FormFieldState field) {
public void _unregister(object field) {
public void _unregister(FormFieldState field) {
this._fields.Remove(field);
}

}
}
public delegate string FormFieldValidator(object value);
public delegate string FormFieldValidator<T>(T value);
public delegate void FormFieldSetter(object newValue);
public delegate void FormFieldSetter<T>(T newValue);
public delegate Widget FormFieldBuilder(FormFieldState field);
public delegate Widget FormFieldBuilder<T>(FormFieldState<T> field) where T : class;
public class FormField : StatefulWidget {
public class FormField<T> : StatefulWidget where T : class {
FormFieldBuilder builder = null,
FormFieldSetter onSaved = null,
FormFieldValidator validator = null,
object initialValue = null,
FormFieldBuilder<T> builder = null,
FormFieldSetter<T> onSaved = null,
FormFieldValidator<T> validator = null,
T initialValue = null,
bool autovalidate = false,
bool enabled = true
) : base(key: key) {

this.enabled = enabled;
}
public readonly FormFieldSetter onSaved;
public readonly FormFieldSetter<T> onSaved;
public readonly FormFieldValidator validator;
public readonly FormFieldValidator<T> validator;
public readonly FormFieldBuilder builder;
public readonly FormFieldBuilder<T> builder;
public readonly object initialValue;
public readonly T initialValue;
public readonly bool autovalidate;

return new FormFieldState();
return new FormFieldState<T>();
public class FormFieldState : State<FormField> {
object _value;
public interface FormFieldState {
void save();
bool validate();
void reset();
}
public class FormFieldState<T> : State<FormField<T>>, FormFieldState where T : class {
T _value;
public object value {
public T value {
get { return this._value; }
}

get { return this._errorText != null; }
}
public virtual void save() {
public void save() {
if (this.widget.onSaved != null) {
this.widget.onSaved(this.value);
}

return !this.hasError;
}
public virtual void didChange(object value) {
public virtual void didChange(T value) {
protected void setValue(object value) {
protected void setValue(T value) {
this._value = value;
}

正在加载...
取消
保存