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 didUpdateWidget(StatefulWidget oldWidget) { base.didUpdateWidget(oldWidget); if (this.widget.controller == null && ((TextField)oldWidget).controller != null) { this._controller = TextEditingController.fromValue(((TextField)oldWidget).controller.value); } else if (this.widget.controller != null && ((TextField)oldWidget).controller == null) { this._controller = null; } bool isEnabled = this.widget.enabled ?? this.widget.decoration?.enabled ?? true; bool wasEnabled = ((TextField)oldWidget).enabled ?? ((TextField)oldWidget).decoration?.enabled ?? true; if (wasEnabled && !isEnabled) { this._effectiveFocusNode.unfocus(); } }
public override void didUpdateWidget(StatefulWidget oldWidget) { oldWidget = (CupertinoTextField)oldWidget; base.didUpdateWidget(oldWidget); if (widget.controller == null && ((CupertinoTextField)oldWidget).controller != null) { _controller = TextEditingController.fromValue(((CupertinoTextField)oldWidget).controller.value); _controller.addListener(updateKeepAlive); } else if (widget.controller != null && ((CupertinoTextField)oldWidget).controller == null) { _controller = null; } bool isEnabled = widget.enabled ?? true; bool wasEnabled = ((CupertinoTextField)oldWidget).enabled ?? true; if (wasEnabled && !isEnabled) { _effectiveFocusNode.unfocus(); } }
public override void didUpdateWidget(StatefulWidget oldWidget) { base.didUpdateWidget(oldWidget); if (widget.controller == null && ((TextField)oldWidget).controller != null) { _controller = TextEditingController.fromValue(((TextField)oldWidget).controller.value); } else if (widget.controller != null && ((TextField)oldWidget).controller == null) { _controller = null; } _effectiveFocusNode.canRequestFocus = _isEnabled; if (_effectiveFocusNode.hasFocus && widget.readOnly != ((TextField)oldWidget).readOnly) { if (_effectiveController.selection.isCollapsed) { _showSelectionHandles = !widget.readOnly; } } }
// The decimal point input-and-parse exists problem. Widget getCardRow(ETransfrom type, bool hasRef) { var xValue = hasRef ? type == ETransfrom.Position ? this.transformRef.position.x.ToString() : type == ETransfrom.Rotation ? this.transformRef.localEulerAngles.x.ToString() : this.transformRef.localScale.x.ToString() : ""; // Using individual TextEditingController to control TextField cursor position. var xValueController = TextEditingController.fromValue( new TextEditingValue(xValue, TextSelection.collapsed(this.oldCursorPosition)) ); var yValue = hasRef ? type == ETransfrom.Position ? this.transformRef.position.y.ToString() : type == ETransfrom.Rotation ? this.transformRef.localEulerAngles.y.ToString() : this.transformRef.localScale.y.ToString() : ""; var yValueController = TextEditingController.fromValue( new TextEditingValue(yValue, TextSelection.collapsed(this.oldCursorPosition)) ); var zValue = hasRef ? type == ETransfrom.Position ? this.transformRef.position.z.ToString() : type == ETransfrom.Rotation ? this.transformRef.localEulerAngles.z.ToString() : this.transformRef.localScale.z.ToString() : ""; var zValueController = TextEditingController.fromValue( new TextEditingValue(zValue, TextSelection.collapsed(this.oldCursorPosition)) ); return(new Column( children: new List <Widget> { new Container( padding: EdgeInsets.symmetric(vertical: 8f), child: new Align( alignment: Alignment.centerLeft, child: new Text( type == ETransfrom.Position ? "Position" : type == ETransfrom.Rotation ? "Rotation" : "Scale", style: new TextStyle(fontSize: 16.0f) ) ) ), new Row( children: new List <Widget> { new Flexible( flex: 8, child: new Container( decoration: new BoxDecoration( color: new Color(0xfff5f5f5)), child: new TextField( decoration: new InputDecoration( border: new UnderlineInputBorder(), contentPadding: EdgeInsets.symmetric( horizontal: 10f, vertical: 5f), labelText: "X" ), controller: xValueController, onChanged: hasRef ? (str) => { // While the TextField value changed, try to parse and assign to transformRef. this.setState(() => { float result = 0; float.TryParse(str, out result); if (str == "" || str[0] == '0') { this.oldCursorPosition = 1; } else { this.oldCursorPosition = xValueController.selection.startPos.offset; } switch (type) { case ETransfrom.Position: var newPos = this.transformRef.position; newPos.x = result; this.transformRef.position = newPos; break; case ETransfrom.Rotation: var newRot = this.transformRef.localEulerAngles; newRot.x = result; this.transformRef.localEulerAngles = newRot; break; case ETransfrom.Scale: var newScale = this.transformRef.localScale; newScale.x = result; this.transformRef.localScale = newScale; break; } }); } : (ValueChanged <string>)null ) )), new Flexible( child: new Container() ), new Flexible( flex: 8, child: new Container( decoration: new BoxDecoration( color: new Color(0xfff5f5f5)), child: new TextField( decoration: new InputDecoration( border: new UnderlineInputBorder(), contentPadding: EdgeInsets.symmetric( horizontal: 10f, vertical: 5f), labelText: "Y" ), controller: yValueController, onChanged: hasRef ? (str) => { this.setState(() => { float result = 0; float.TryParse(str, out result); if (str == "" || str[0] == '0') { this.oldCursorPosition = 1; } else { this.oldCursorPosition = yValueController.selection.startPos.offset; } switch (type) { case ETransfrom.Position: var newPos = this.transformRef.position; newPos.y = result; this.transformRef.position = newPos; break; case ETransfrom.Rotation: var newRot = this.transformRef.localEulerAngles; newRot.y = result; this.transformRef.localEulerAngles = newRot; break; case ETransfrom.Scale: var newScale = this.transformRef.localScale; newScale.y = result; this.transformRef.localScale = newScale; break; } }); } : (ValueChanged <string>)null ) )), new Flexible( child: new Container() ), new Flexible( flex: 8, child: new Container( decoration: new BoxDecoration( color: new Color(0xfff5f5f5)), child: new TextField( decoration: new InputDecoration( border: new UnderlineInputBorder(), contentPadding: EdgeInsets.symmetric( horizontal: 10f, vertical: 5f), labelText: "Z" ), controller: zValueController, onChanged: hasRef ? (str) => { this.setState(() => { float result = 0; float.TryParse(str, out result); if (str == "" || str[0] == '0') { this.oldCursorPosition = 1; } else { this.oldCursorPosition = zValueController.selection.startPos.offset; } switch (type) { case ETransfrom.Position: var newPos = this.transformRef.position; newPos.z = result; this.transformRef.position = newPos; break; case ETransfrom.Rotation: var newRot = this.transformRef.localEulerAngles; newRot.z = result; this.transformRef.localEulerAngles = newRot; break; case ETransfrom.Scale: var newScale = this.transformRef.localScale; newScale.z = result; this.transformRef.localScale = newScale; break; } }); } : (ValueChanged <string>)null ) )) } ) } )); }