您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
66 行
2.3 KiB
66 行
2.3 KiB
using Unity.UIWidgets.material;
|
|
using Unity.UIWidgets.painting;
|
|
using Unity.UIWidgets.ui;
|
|
using Unity.UIWidgets.widgets;
|
|
using UnityEngine;
|
|
using DialogUtils = Unity.UIWidgets.material.DialogUtils;
|
|
|
|
namespace UIWidgetsSample {
|
|
public class TextFieldSample : UIWidgetsSamplePanel {
|
|
protected override void Awake() {
|
|
base.Awake();
|
|
FontManager.instance.addFont(Resources.Load<Font>(path: "MaterialIcons-Regular"), "Material Icons");
|
|
}
|
|
|
|
protected override Widget createWidget() {
|
|
return new MaterialApp(
|
|
title: "Text Fields",
|
|
home: new MyCustomForm()
|
|
);
|
|
}
|
|
}
|
|
|
|
class MyCustomForm : StatefulWidget {
|
|
public override State createState() {
|
|
return new _MyCustomFormState();
|
|
}
|
|
}
|
|
|
|
class _MyCustomFormState : State<MyCustomForm> {
|
|
readonly TextEditingController myController = new TextEditingController();
|
|
|
|
public override void dispose() {
|
|
this.myController.dispose();
|
|
base.dispose();
|
|
}
|
|
|
|
public override Widget build(BuildContext context) {
|
|
return new Scaffold(
|
|
appBar: new AppBar(
|
|
title: new Text("Retrieve Text Input")
|
|
),
|
|
body: new Padding(
|
|
padding: EdgeInsets.all(16.0f),
|
|
child: new TextField(controller: this.myController)
|
|
),
|
|
floatingActionButton: new FloatingActionButton(
|
|
// When the user presses the button, show an alert dialog with the
|
|
// text the user has typed into our text field.
|
|
onPressed: () => {
|
|
DialogUtils.showDialog(
|
|
context: context,
|
|
builder: (_context) => {
|
|
return new AlertDialog(
|
|
// Retrieve the text the user has typed in using our
|
|
// TextEditingController
|
|
content: new Text(this.myController.text)
|
|
);
|
|
});
|
|
},
|
|
tooltip: "Show me the value",
|
|
child: new Icon(Icons.search)
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|