@@ -69,8 +69,10 @@ enum ETransfrom {
69
69
Scale
70
70
}
71
71
72
+ // make custom control of cursor position in TextField.
72
73
int oldCursorPosition = 0 ;
73
74
75
+ // The decimal point input-and-parse exists problem.
74
76
Widget getCardRow ( ETransfrom type , bool hasRef ) {
75
77
var xValue = hasRef
76
78
? type == ETransfrom . Position
@@ -79,15 +81,15 @@ Widget getCardRow(ETransfrom type, bool hasRef) {
79
81
? this . transformRef . localEulerAngles . x . ToString ( )
80
82
: this . transformRef . localScale . x . ToString ( )
81
83
: "" ;
82
-
84
+ // Using individual TextEditingController to control TextField cursor position.
83
85
var xValueController = TextEditingController . fromValue (
84
86
new TextEditingValue ( xValue , TextSelection . collapsed ( this . oldCursorPosition ) )
85
87
) ;
86
88
87
89
var yValue = hasRef
88
90
? type == ETransfrom . Position
89
91
? this . transformRef . position . y . ToString ( )
90
- : type == ETransfrom . Scale
92
+ : type == ETransfrom . Rotation
91
93
? this . transformRef . localEulerAngles . y . ToString ( )
92
94
: this . transformRef . localScale . y . ToString ( )
93
95
: "" ;
@@ -139,10 +141,17 @@ Widget getCardRow(ETransfrom type, bool hasRef) {
139
141
controller : xValueController ,
140
142
onChanged : hasRef
141
143
? ( str ) => {
144
+ // While the TextField value changed, try to parse and assign to transformRef.
142
145
this . setState ( ( ) => {
143
146
float result = 0 ;
144
147
float . TryParse ( str , out result ) ;
145
- this . oldCursorPosition = xValueController . selection . startPos . offset ;
148
+ if ( str == "" || str [ 0 ] == '0' ) {
149
+ this . oldCursorPosition = 1 ;
150
+ }
151
+ else {
152
+ this . oldCursorPosition =
153
+ xValueController . selection . startPos . offset ;
154
+ }
146
155
147
156
switch ( type ) {
148
157
case ETransfrom . Position :
@@ -188,7 +197,13 @@ Widget getCardRow(ETransfrom type, bool hasRef) {
188
197
this . setState ( ( ) => {
189
198
float result = 0 ;
190
199
float . TryParse ( str , out result ) ;
191
- this . oldCursorPosition = yValueController . selection . startPos . offset ;
200
+ if ( str == "" || str [ 0 ] == '0' ) {
201
+ this . oldCursorPosition = 1 ;
202
+ }
203
+ else {
204
+ this . oldCursorPosition =
205
+ yValueController . selection . startPos . offset ;
206
+ }
192
207
193
208
switch ( type ) {
194
209
case ETransfrom . Position :
@@ -234,8 +249,13 @@ Widget getCardRow(ETransfrom type, bool hasRef) {
234
249
this . setState ( ( ) => {
235
250
float result = 0 ;
236
251
float . TryParse ( str , out result ) ;
237
- this . oldCursorPosition = zValueController . selection . startPos . offset ;
238
- Debug . Log ( result ) ;
252
+ if ( str == "" || str [ 0 ] == '0' ) {
253
+ this . oldCursorPosition = 1 ;
254
+ }
255
+ else {
256
+ this . oldCursorPosition =
257
+ zValueController . selection . startPos . offset ;
258
+ }
239
259
240
260
switch ( type ) {
241
261
case ETransfrom . Position :
@@ -292,11 +312,15 @@ public override Widget build(BuildContext context) {
292
312
mainAxisSize : MainAxisSize . min ,
293
313
children : new List < Widget > {
294
314
new UnityObjectDetector (
315
+ // When receiving a GameObject, get its transfrom.
295
316
onRelease : ( details ) => {
296
317
this . setState ( ( ) => {
297
- this . objectRef = details . objectReferences [ 0 ] as GameObject ;
298
- if ( this . objectRef ) {
299
- this . transformRef = this . objectRef . transform ;
318
+ var gameObj = details . objectReferences [ 0 ] as GameObject ;
319
+ if ( gameObj ) {
320
+ this . objectRef = gameObj ;
321
+ if ( this . objectRef ) {
322
+ this . transformRef = this . objectRef . transform ;
323
+ }
300
324
}
301
325
} ) ;
302
326
} ,
0 commit comments