8
8
using Unity . UIWidgets . widgets ;
9
9
using UnityEngine ;
10
10
using Color = Unity . UIWidgets . ui . Color ;
11
- using TextStyle = Unity . UIWidgets . painting . TextStyle ;
12
11
13
12
namespace UIWidgetsSample {
14
13
public class TextInputSample : UIWidgetsSamplePanel {
15
-
16
14
class _TextInputSample : StatefulWidget {
17
15
public readonly string title ;
18
16
@@ -25,12 +23,12 @@ public override State createState() {
25
23
}
26
24
}
27
25
28
- protected override Widget createWidget ( ) {
26
+ protected override Widget createWidget ( ) {
29
27
return new WidgetsApp (
30
28
home : new EditableInputTypeWidget ( ) ,
31
29
pageRouteBuilder : this . pageRouteBuilder ) ;
32
30
}
33
-
31
+
34
32
35
33
class _TextInputSampleState : State < _TextInputSample > {
36
34
TextEditingController titleController = new TextEditingController ( "" ) ;
@@ -138,7 +136,7 @@ public override State createState() {
138
136
return new _EditableInputTypeWidgetState ( ) ;
139
137
}
140
138
}
141
-
139
+
142
140
class _EditableInputTypeWidgetState : State < EditableInputTypeWidget > {
143
141
Widget rowWidgets ( string title , Widget widget ) {
144
142
return new Container (
@@ -151,72 +149,83 @@ Widget rowWidgets(string title, Widget widget) {
151
149
}
152
150
) ) ;
153
151
}
154
-
152
+
155
153
void textSubmitted ( string text ) {
156
154
Debug . Log ( $ "text submitted { text } ") ;
157
155
}
158
156
159
157
List < Widget > buildInputs ( bool unityKeyboard ) {
160
- List < Widget > widgets = new List < Widget > ( ) ;
158
+ List < Widget > widgets = new List < Widget > ( ) ;
161
159
var style = new TextStyle ( ) ;
162
160
var cursorColor = new Color ( 0xFF000000 ) ;
163
161
var selectionColor = new Color ( 0xFF6F6F6F ) ;
164
-
162
+
165
163
widgets . Add ( this . rowWidgets ( "Default" , new EditStateProvider ( builder : ( ( buildContext , controller , node ) =>
166
- new EditableText ( controller , node , style , cursorColor , Colors . transparent , selectionColor : selectionColor , onSubmitted : this . textSubmitted
167
- , unityTouchKeyboard : unityKeyboard , selectionControls : MaterialUtils . materialTextSelectionControls ) ) ) ) ) ;
164
+ new EditableText ( controller , node , style , cursorColor , Colors . blue ,
165
+ selectionColor : selectionColor , onSubmitted : this . textSubmitted
166
+ , unityTouchKeyboard : unityKeyboard ,
167
+ selectionControls : MaterialUtils . materialTextSelectionControls ,
168
+ cursorWidth : 5.0f , cursorRadius : Radius . circular ( 2.5f ) , cursorOpacityAnimates : true , paintCursorAboveText : true ) ) ) ) ) ;
168
169
169
170
widgets . Add ( this . rowWidgets ( "Multiple Line" , new EditStateProvider (
170
171
builder : ( ( buildContext , controller , node ) =>
171
- new EditableText ( controller , node , style , cursorColor , Colors . transparent , selectionColor : selectionColor , maxLines : 4 ,
172
+ new EditableText ( controller , node , style , cursorColor , Colors . transparent ,
173
+ selectionColor : selectionColor , maxLines : 4 ,
172
174
onSubmitted : this . textSubmitted , unityTouchKeyboard : unityKeyboard ,
173
175
selectionControls : MaterialUtils . materialTextSelectionControls ) ) ) ) ) ;
174
176
175
177
widgets . Add ( this . rowWidgets ( "ObscureText" , new EditStateProvider (
176
178
builder : ( ( buildContext , controller , node ) =>
177
- new EditableText ( controller , node , style , cursorColor , Colors . transparent , selectionColor : selectionColor , obscureText : true ,
178
- onSubmitted : this . textSubmitted , unityTouchKeyboard : unityKeyboard ,
179
+ new EditableText ( controller , node , style , cursorColor , Colors . transparent ,
180
+ selectionColor : selectionColor , obscureText : true ,
181
+ onSubmitted : this . textSubmitted , unityTouchKeyboard : unityKeyboard ,
179
182
selectionControls : MaterialUtils . materialTextSelectionControls ) ) ) ) ) ;
180
183
181
184
widgets . Add ( this . rowWidgets ( "Number" , new EditStateProvider ( builder : ( ( buildContext , controller , node ) =>
182
- new EditableText ( controller , node , style , cursorColor , Colors . transparent , selectionColor : selectionColor , keyboardType : TextInputType . number ,
185
+ new EditableText ( controller , node , style , cursorColor , Colors . transparent ,
186
+ selectionColor : selectionColor , keyboardType : TextInputType . number ,
183
187
onSubmitted : this . textSubmitted , unityTouchKeyboard : unityKeyboard ,
184
188
selectionControls : MaterialUtils . materialTextSelectionControls ) ) ) ) ) ;
185
189
186
190
widgets . Add ( this . rowWidgets ( "Phone" , new EditStateProvider ( builder : ( ( buildContext , controller , node ) =>
187
- new EditableText ( controller , node , style , cursorColor , Colors . transparent , selectionColor : selectionColor , keyboardType : TextInputType . phone ,
191
+ new EditableText ( controller , node , style , cursorColor , Colors . transparent ,
192
+ selectionColor : selectionColor , keyboardType : TextInputType . phone ,
188
193
onSubmitted : this . textSubmitted , unityTouchKeyboard : unityKeyboard ,
189
194
selectionControls : MaterialUtils . materialTextSelectionControls ) ) ) ) ) ;
190
195
191
196
widgets . Add ( this . rowWidgets ( "Email" , new EditStateProvider ( builder : ( ( buildContext , controller , node ) =>
192
- new EditableText ( controller , node , style , cursorColor , Colors . transparent , selectionColor : selectionColor , keyboardType : TextInputType . emailAddress ,
197
+ new EditableText ( controller , node , style , cursorColor , Colors . transparent ,
198
+ selectionColor : selectionColor , keyboardType : TextInputType . emailAddress ,
193
199
onSubmitted : this . textSubmitted , unityTouchKeyboard : unityKeyboard ,
194
200
selectionControls : MaterialUtils . materialTextSelectionControls ) ) ) ) ) ;
195
201
196
202
widgets . Add ( this . rowWidgets ( "Url" , new EditStateProvider ( builder : ( ( buildContext , controller , node ) =>
197
- new EditableText ( controller , node , style , cursorColor , Colors . transparent , selectionColor : selectionColor , keyboardType : TextInputType . url ,
203
+ new EditableText ( controller , node , style , cursorColor , Colors . transparent ,
204
+ selectionColor : selectionColor , keyboardType : TextInputType . url ,
198
205
onSubmitted : this . textSubmitted , unityTouchKeyboard : unityKeyboard ,
199
206
selectionControls : MaterialUtils . materialTextSelectionControls ) ) ) ) ) ;
200
207
return widgets ;
201
208
}
202
-
209
+
203
210
public override Widget build ( BuildContext context ) {
204
211
List < Widget > widgets = new List < Widget > ( ) ;
205
-
206
- widgets . Add ( new Text ( "UIWidgets Touch Keyboard" , style : new TextStyle ( fontSize : 20 , height : 2.0f ) , textAlign : TextAlign . center ) ) ;
212
+
213
+ widgets . Add ( new Text ( "UIWidgets Touch Keyboard" , style : new TextStyle ( fontSize : 20 , height : 2.0f ) ,
214
+ textAlign : TextAlign . center ) ) ;
207
215
widgets . AddRange ( this . buildInputs ( false ) ) ;
208
-
209
- widgets . Add ( new Text ( "Unity Touch Keyboard" , style : new TextStyle ( fontSize : 20 , height : 2.0f ) , textAlign : TextAlign . center ) ) ;
216
+
217
+ widgets . Add ( new Text ( "Unity Touch Keyboard" , style : new TextStyle ( fontSize : 20 , height : 2.0f ) ,
218
+ textAlign : TextAlign . center ) ) ;
210
219
widgets . AddRange ( this . buildInputs ( true ) ) ;
211
-
220
+
212
221
return new Container (
213
222
padding : EdgeInsets . all ( 12 ) ,
214
223
child : new SingleChildScrollView ( child : new Column (
215
- crossAxisAlignment : CrossAxisAlignment . stretch ,
216
- children : widgets ) ) ) ;
224
+ crossAxisAlignment : CrossAxisAlignment . stretch ,
225
+ children : widgets ) ) ) ;
217
226
}
218
-
219
227
}
228
+
220
229
public class EditStateProvider : StatefulWidget {
221
230
public delegate EditableText EditableBuilder ( BuildContext context ,
222
231
TextEditingController controller , FocusNode focusNode ) ;
0 commit comments