浏览代码

Tmp store.

/main
Yuncong Zhang 6 年前
当前提交
fb0c4173
共有 5 个文件被更改,包括 198 次插入39 次删除
  1. 14
      Runtime/material/dropdown.cs
  2. 2
      Runtime/material/text_field.cs
  3. 62
      Runtime/widgets/form.cs
  4. 156
      Runtime/material/text_form_field.cs
  5. 3
      Runtime/material/text_form_field.cs.meta

14
Runtime/material/dropdown.cs


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

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

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

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

2
Runtime/material/text_field.cs


properties.add(new EnumProperty<TextCapitalization>("textCapitalization", this.textCapitalization, defaultValue: TextCapitalization.none));
properties.add(new EnumProperty<TextAlign>("textAlign", this.textAlign, defaultValue: TextAlign.left));
properties.add(new EnumProperty<TextDirection>("textDirection", this.textDirection, defaultValue: null));
properties.add(new FloatProperty("cursorWidth", this.cursorWidth, defaultValue: 2.0));
properties.add(new FloatProperty("cursorWidth", this.cursorWidth, defaultValue: 2.0f));
properties.add(new DiagnosticsProperty<Radius>("cursorRadius", this.cursorRadius, defaultValue: null));
properties.add(new DiagnosticsProperty<Color>("cursorColor", this.cursorColor, defaultValue: null));
properties.add(new DiagnosticsProperty<Brightness?>("keyboardAppearance", this.keyboardAppearance, defaultValue: null));

62
Runtime/widgets/form.cs


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

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

);
}
void save() {
foreach (FormFieldState<dynamic> field in this._fields) {
public void save() {
foreach (FormFieldState field in this._fields) {
void reset() {
foreach (FormFieldState<dynamic> field in this._fields) {
public void reset() {
foreach (FormFieldState field in this._fields) {
field.reset();
}

bool validate() {
public bool validate() {
this._forceRebuild();
return this._validate();
}

foreach (FormFieldState<dynamic> field in this._fields) {
foreach (FormFieldState field in this._fields) {
hasError = !field.validate() || hasError;
}

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

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

return new FormFieldState<T>();
return new FormFieldState();
public class FormFieldState<T> : State<FormField<T>> where T : class {
T _value;
public class FormFieldState : State<FormField> {
object _value;
public T value {
public object value {
get { return this._value; }
}

get { return this._errorText != null; }
}
public void save() {
public virtual void save() {
public void reset() {
public virtual void reset() {
this.setState(() => {
this._value = this.widget.initialValue;
this._errorText = null;

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

}
public override void deactivate() {
Form.of(this.context)?._unregister(this as FormFieldState<dynamic>);
Form.of(this.context)?._unregister(this);
base.deactivate();
}

}
Form.of(context)?._register(this as FormFieldState<dynamic>);
Form.of(context)?._register(this);
return this.widget.builder(this);
}
}

156
Runtime/material/text_form_field.cs


using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace UIWidgets.Runtime.material {
public class TextFormField : FormField {
public TextFormField(
Key key = null,
TextEditingController controller = null,
string initialValue = null,
FocusNode focusNode = null,
InputDecoration decoration = null,
TextInputType keyboardType = null,
TextCapitalization textCapitalization = TextCapitalization.none,
TextInputAction? textInputAction = null,
TextStyle style = null,
TextDirection? textDirection = null,
TextAlign textAlign = TextAlign.left,
bool autofocus = false,
bool obscureText = false,
bool autocorrect = true,
bool autovalidate = false,
bool maxLengthEnforced = true,
int maxLines = 1,
int? maxLength = null,
VoidCallback onEditingComplete = null,
ValueChanged<string> onFieldSubmitted = null,
FormFieldSetter onSaved = null,
FormFieldValidator validator = null,
List<TextInputFormatter> inputFormatters = null,
bool enabled = true,
float cursorWidth = 2.0f,
Radius cursorRadius = null,
Color cursorColor = null,
Brightness? keyboardAppearance = null,
EdgeInsets scrollPadding = null,
bool enableInteractiveSelection = true,
InputCounterWidgetBuilder buildCounter = null
) : base(
key: key,
initialValue: controller != null ? controller.text : (initialValue ?? ""),
onSaved: onSaved,
validator: validator,
autovalidate: autovalidate,
enabled: enabled,
builder: (FormFieldState field) => {
_TextFormFieldState state = (_TextFormFieldState) field;
InputDecoration effectiveDecoration = (decoration ?? new InputDecoration())
.applyDefaults(Theme.of(field.context).inputDecorationTheme);
return new TextField(
controller: state._effectiveController,
focusNode: focusNode,
decoration: effectiveDecoration.copyWith(errorText: field.errorText),
keyboardType: keyboardType,
textInputAction: textInputAction,
style: style,
textAlign: textAlign,
textDirection: textDirection ?? TextDirection.ltr,
textCapitalization: textCapitalization,
autofocus: autofocus,
obscureText: obscureText,
autocorrect: autocorrect,
maxLengthEnforced: maxLengthEnforced,
maxLines: maxLines,
maxLength: maxLength,
onChanged: field.didChange,
onEditingComplete: onEditingComplete,
onSubmitted: onFieldSubmitted,
inputFormatters: inputFormatters,
enabled: enabled,
cursorWidth: cursorWidth,
cursorRadius: cursorRadius,
cursorColor: cursorColor,
scrollPadding: scrollPadding ?? EdgeInsets.all(20.0f),
keyboardAppearance: keyboardAppearance,
enableInteractiveSelection: enableInteractiveSelection,
buildCounter: buildCounter
);
}
) {
D.assert(initialValue == null || controller == null);
D.assert(maxLines > 0);
D.assert(maxLength == null || maxLength > 0);
this.controller = controller;
}
public readonly TextEditingController controller;
public override State createState() {
return new _TextFormFieldState();
}
}
class _TextFormFieldState : FormFieldState {
TextEditingController _controller;
public TextEditingController _effectiveController {
get { return this.widget.controller ?? this._controller; }
}
public new TextFormField widget {
get { return (TextFormField) base.widget; }
}
public override void initState() {
base.initState();
if (this.widget.controller == null) {
this._controller = new TextEditingController(text: (string) this.widget.initialValue);
}
else {
this.widget.controller.addListener(this._handleControllerChanged);
}
}
public override void didUpdateWidget(StatefulWidget _oldWidget) {
TextFormField oldWidget = _oldWidget as TextFormField;
base.didUpdateWidget(oldWidget);
if (this.widget.controller != oldWidget.controller) {
oldWidget.controller?.removeListener(this._handleControllerChanged);
this.widget.controller?.addListener(this._handleControllerChanged);
if (oldWidget.controller != null && this.widget.controller == null) {
this._controller = TextEditingController.fromValue(oldWidget.controller.value);
}
if (this.widget.controller != null) {
this.setValue(this.widget.controller.text);
if (oldWidget.controller == null) {
this._controller = null;
}
}
}
}
public override void dispose() {
this.widget.controller?.removeListener(this._handleControllerChanged);
base.dispose();
}
public override void reset() {
base.reset();
this.setState(() => { this._effectiveController.text = (string) this.widget.initialValue; });
}
void _handleControllerChanged() {
if (this._effectiveController.text != this.value) {
this.didChange(this._effectiveController.text);
}
}
}
}

3
Runtime/material/text_form_field.cs.meta


fileFormatVersion: 2
guid: 0a9f1467be1c4653b3dbf8a1c7209f70
timeCreated: 1557304128
正在加载...
取消
保存