siyao
4 年前
当前提交
7ec28d6c
共有 11 个文件被更改,包括 764 次插入 和 31 次删除
-
2Samples/UIWidgetsSamples_2019_4/Assets/Script/TextFieldTest.cs
-
45com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
-
2com.unity.uiwidgets/Runtime/material/input_decorator.cs
-
9com.unity.uiwidgets/Runtime/services/keyboard.cs
-
4com.unity.uiwidgets/Runtime/widgets/framework.cs
-
89Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/TextFieldSample.cs
-
369Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/TextInputSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/TextInputSample.cs.meta
-
243Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/ToDoAppSample.cs
-
21Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/UIWidgetsSamplePanel.cs
-
0/Samples/UIWidgetsSamples_2019_4/Assets/Script/TextFieldTest.cs
|
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample |
|||
{ |
|||
public class TextFieldSample : UIWidgetsSamplePanel |
|||
{ |
|||
protected override void main() |
|||
{ |
|||
ui_.runApp( |
|||
new MaterialApp( |
|||
title: "Text Fields", |
|||
home: new MyCustomForm() |
|||
) |
|||
); |
|||
} |
|||
|
|||
protected new void OnEnable() |
|||
{ |
|||
base.OnEnable(); |
|||
// TODO: add font
|
|||
// FontManager.instance.addFont(Resources.Load<Font>(path: "fonts/MaterialIcons-Regular"), "Material Icons");
|
|||
} |
|||
} |
|||
|
|||
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, |
|||
autofocus: true, |
|||
decoration: new InputDecoration( |
|||
hintText: "hinthere", |
|||
labelText: "pwd", |
|||
prefixIcon: new Icon(Unity.UIWidgets.material.Icons.search) |
|||
) |
|||
) |
|||
), |
|||
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: () => |
|||
{ |
|||
material_.showDialog<object>( |
|||
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) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using uiwidgets; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.service; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample |
|||
{ |
|||
public class TextInputSample : UIWidgetsSamplePanel |
|||
{ |
|||
protected override void main() |
|||
{ |
|||
ui_.runApp( |
|||
new MaterialApp( |
|||
home: new EditableInputTypeWidget() |
|||
) |
|||
); |
|||
} |
|||
|
|||
protected new void OnEnable() |
|||
{ |
|||
base.OnEnable(); |
|||
} |
|||
|
|||
class _TextInputSample : StatefulWidget |
|||
{ |
|||
public readonly string title; |
|||
|
|||
public _TextInputSample(Key key = null, string title = null) : base(key) |
|||
{ |
|||
this.title = title; |
|||
} |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new _TextInputSampleState(); |
|||
} |
|||
} |
|||
|
|||
class _TextInputSampleState : State<_TextInputSample> |
|||
{ |
|||
TextEditingController titleController = new TextEditingController(""); |
|||
TextEditingController descController = new TextEditingController(""); |
|||
FocusNode _titleFocusNode; |
|||
FocusNode _descFocusNode; |
|||
|
|||
public override void initState() |
|||
{ |
|||
base.initState(); |
|||
this._titleFocusNode = new FocusNode(); |
|||
this._descFocusNode = new FocusNode(); |
|||
} |
|||
|
|||
public override void dispose() |
|||
{ |
|||
this._titleFocusNode.dispose(); |
|||
this._descFocusNode.dispose(); |
|||
base.dispose(); |
|||
} |
|||
|
|||
Widget title() |
|||
{ |
|||
return new Container(child: new Text(this.widget.title ?? "", textAlign: TextAlign.center, |
|||
style: new TextStyle(fontSize: 24, fontWeight: FontWeight.w700)), |
|||
margin: EdgeInsets.only(bottom: 20)); |
|||
} |
|||
|
|||
Widget titleInput() |
|||
{ |
|||
return new Row( |
|||
children: new List<Widget>( |
|||
) |
|||
{ |
|||
new SizedBox(width: 100, child: new Text("Title")), |
|||
new Flexible(child: new Container( |
|||
decoration: new BoxDecoration(border: Border.all(new Color(0xFF000000), 1)), |
|||
padding: EdgeInsets.fromLTRB(8, 0, 8, 0), |
|||
child: new EditableText(maxLines: 1, |
|||
controller: this.titleController, |
|||
selectionControls: MaterialUtils.materialTextSelectionControls, |
|||
backgroundCursorColor: Colors.transparent, |
|||
autofocus: true, |
|||
focusNode: new FocusNode(), |
|||
style: new TextStyle( |
|||
fontSize: 18, |
|||
height: 1.5f, |
|||
color: new Color(0xFF1389FD) |
|||
), |
|||
selectionColor: Color.fromARGB(255, 255, 0, 0), |
|||
cursorColor: Color.fromARGB(255, 0, 0, 0)) |
|||
)), |
|||
} |
|||
); |
|||
} |
|||
|
|||
Widget descInput() |
|||
{ |
|||
return new Container( |
|||
margin: EdgeInsets.fromLTRB(0, 10, 0, 10), |
|||
child: new Row( |
|||
children: new List<Widget>( |
|||
) |
|||
{ |
|||
new SizedBox(width: 100, child: new Text("Description")), |
|||
new Flexible(child: new Container( |
|||
height: 200, |
|||
decoration: new BoxDecoration(border: Border.all(new Color(0xFF000000), 1)), |
|||
padding: EdgeInsets.fromLTRB(8, 0, 8, 0), |
|||
child: new EditableText(maxLines: 200, |
|||
controller: this.descController, |
|||
backgroundCursorColor: Colors.transparent, |
|||
selectionControls: MaterialUtils.materialTextSelectionControls, |
|||
focusNode: new FocusNode(), |
|||
style: new TextStyle( |
|||
fontSize: 18, |
|||
height: 1.5f, |
|||
color: new Color(0xFF1389FD) |
|||
), |
|||
selectionColor: Color.fromARGB(255, 255, 0, 0), |
|||
cursorColor: Color.fromARGB(255, 0, 0, 0)) |
|||
)), |
|||
} |
|||
)); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
var container = new Container( |
|||
padding: EdgeInsets.all(10), |
|||
decoration: new BoxDecoration(color: new Color(0x7F000000), |
|||
border: Border.all(color: Color.fromARGB(255, 255, 0, 0), width: 5), |
|||
borderRadius: BorderRadius.all(2)), |
|||
child: new Column( |
|||
crossAxisAlignment: CrossAxisAlignment.stretch, |
|||
children: new List<Widget> |
|||
{ |
|||
this.title(), |
|||
this.titleInput(), |
|||
this.descInput(), |
|||
} |
|||
) |
|||
); |
|||
return container; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class EditableInputTypeWidget : StatefulWidget |
|||
{ |
|||
public EditableInputTypeWidget(Key key = null) : base(key) |
|||
{ |
|||
} |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new _EditableInputTypeWidgetState(); |
|||
} |
|||
} |
|||
|
|||
class _EditableInputTypeWidgetState : State<EditableInputTypeWidget> |
|||
{ |
|||
Widget rowWidgets(string title, Widget widget) |
|||
{ |
|||
return new Container( |
|||
height: 80, |
|||
child: new Row( |
|||
children: new List<Widget> |
|||
{ |
|||
new Container(width: 100, |
|||
child: new Text(title, |
|||
style: new TextStyle(fontSize: 14, height: 2.0f, color: Colors.black, |
|||
decoration: TextDecoration.none))), |
|||
new Flexible(child: new Container(child: widget, padding: EdgeInsets.all(4), decoration: |
|||
new BoxDecoration(border: Border.all(color: Color.black)))) |
|||
} |
|||
)); |
|||
} |
|||
|
|||
void textSubmitted(string text) |
|||
{ |
|||
Debug.Log($"text submitted {text}"); |
|||
} |
|||
|
|||
List<Widget> buildInputs(bool unityKeyboard) |
|||
{ |
|||
List<Widget> widgets = new List<Widget>(); |
|||
var style = new TextStyle(); |
|||
var cursorColor = new Color(0xFF000000); |
|||
var selectionColor = new Color(0xFF6F6F6F); |
|||
|
|||
widgets.Add(this.rowWidgets("Default", new EditStateProvider(builder: ((buildContext, controller, node) => |
|||
new EditableText(controller: controller, focusNode: node, style: style, cursorColor: cursorColor, |
|||
backgroundCursorColor: Colors.blue, |
|||
selectionColor: selectionColor, onSubmitted: this.textSubmitted |
|||
, unityTouchKeyboard: unityKeyboard, |
|||
selectionControls: MaterialUtils.materialTextSelectionControls, |
|||
cursorWidth: 5.0f, cursorRadius: Radius.circular(2.5f), cursorOpacityAnimates: true, |
|||
paintCursorAboveText: true))))); |
|||
|
|||
widgets.Add(this.rowWidgets("Multiple Line", new EditStateProvider( |
|||
builder: ((buildContext, controller, node) => |
|||
new EditableText(controller: controller, focusNode: node, style: style, cursorColor: cursorColor, |
|||
backgroundCursorColor: Colors.transparent, |
|||
selectionColor: selectionColor, maxLines: 4, |
|||
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, |
|||
selectionControls: MaterialUtils.materialTextSelectionControls |
|||
// ,
|
|||
// globalKeyEventHandler: (evt, enableCustomAction) => {
|
|||
// //customized key event handler which may swallow input keys to the editable and
|
|||
// //perform customized functionality
|
|||
// //
|
|||
// //evt is the input rawKeyEvent
|
|||
// //you should perform any customized functionality within the closure of "if(enableCustomAction) {}",
|
|||
// //otherwise it could be performed multiple times for a single key event.
|
|||
// //
|
|||
// //Very Important: for any input event, please ensure that all the output RawInputKeyResponse is the same
|
|||
// //regardless of the value of enableCustomAction, otherwise the behavior of this handler would become
|
|||
// //wrong and unpredictable
|
|||
// if (evt.data.unityEvent.keyCode == KeyCode.UpArrow) {
|
|||
// if (enableCustomAction) {
|
|||
// Debug.Log("UpUpUp");
|
|||
// }
|
|||
//
|
|||
// return RawInputKeyResponse.swallowResponse;
|
|||
// }
|
|||
//
|
|||
// if (evt.data.unityEvent.keyCode == KeyCode.DownArrow) {
|
|||
// if (enableCustomAction) {
|
|||
// Debug.Log("UpUpUp");
|
|||
// }
|
|||
//
|
|||
// return RawInputKeyResponse.swallowResponse;
|
|||
// }
|
|||
//
|
|||
// if (evt.data.unityEvent.character == '\n' ||
|
|||
// evt.data.unityEvent.character == '\r' ||
|
|||
// evt.data.unityEvent.character == 3 ||
|
|||
// evt.data.unityEvent.character == 10) {
|
|||
//
|
|||
// if (evt.data.unityEvent.shift) {
|
|||
// if (enableCustomAction) {
|
|||
// Debug.Log("shift return >>>");
|
|||
// }
|
|||
// return new RawInputKeyResponse(true, evt.data.unityEvent.character, inputAction: TextInputAction.newline);
|
|||
// }
|
|||
// else {
|
|||
// if (enableCustomAction) {
|
|||
// Debug.Log("send !!!!");
|
|||
// }
|
|||
// return RawInputKeyResponse.swallowResponse;
|
|||
// }
|
|||
// }
|
|||
//
|
|||
// return RawInputKeyResponse.convert(evt);
|
|||
// }
|
|||
))))); |
|||
|
|||
widgets.Add(this.rowWidgets("ObscureText", new EditStateProvider( |
|||
builder: ((buildContext, controller, node) => |
|||
new EditableText(controller: controller, focusNode: node, style: style, cursorColor: cursorColor, |
|||
backgroundCursorColor: Colors.transparent, |
|||
selectionColor: selectionColor, obscureText: true, |
|||
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, |
|||
selectionControls: MaterialUtils.materialTextSelectionControls))))); |
|||
|
|||
widgets.Add(this.rowWidgets("Number", new EditStateProvider(builder: ((buildContext, controller, node) => |
|||
new EditableText(controller: controller, focusNode: node, style: style, cursorColor: cursorColor, |
|||
backgroundCursorColor: Colors.transparent, |
|||
selectionColor: selectionColor, keyboardType: TextInputType.number, |
|||
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, |
|||
selectionControls: MaterialUtils.materialTextSelectionControls))))); |
|||
|
|||
widgets.Add(this.rowWidgets("Phone", new EditStateProvider(builder: ((buildContext, controller, node) => |
|||
new EditableText(controller: controller, focusNode: node, style: style, cursorColor: cursorColor, |
|||
backgroundCursorColor: Colors.transparent, |
|||
selectionColor: selectionColor, keyboardType: TextInputType.phone, |
|||
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, |
|||
selectionControls: MaterialUtils.materialTextSelectionControls))))); |
|||
|
|||
widgets.Add(this.rowWidgets("Email", new EditStateProvider(builder: ((buildContext, controller, node) => |
|||
new EditableText(controller: controller, focusNode: node, style: style, cursorColor: cursorColor, |
|||
backgroundCursorColor: Colors.transparent, |
|||
selectionColor: selectionColor, keyboardType: TextInputType.emailAddress, |
|||
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, |
|||
selectionControls: MaterialUtils.materialTextSelectionControls))))); |
|||
|
|||
widgets.Add(this.rowWidgets("Url", new EditStateProvider(builder: ((buildContext, controller, node) => |
|||
new EditableText(controller: controller, focusNode: node, style: style, cursorColor: cursorColor, |
|||
backgroundCursorColor: Colors.transparent, |
|||
selectionColor: selectionColor, keyboardType: TextInputType.url, |
|||
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard, |
|||
selectionControls: MaterialUtils.materialTextSelectionControls))))); |
|||
return widgets; |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
List<Widget> widgets = new List<Widget>(); |
|||
|
|||
widgets.Add(new Text("UIWidgets Touch Keyboard", |
|||
style: new TextStyle(fontSize: 20, height: 2.0f, color: Colors.black, decoration: TextDecoration.none), |
|||
textAlign: TextAlign.center)); |
|||
widgets.AddRange(this.buildInputs(false)); |
|||
|
|||
widgets.Add(new Text("Unity Touch Keyboard", |
|||
style: new TextStyle(fontSize: 20, height: 2.0f, color: Colors.black, decoration: TextDecoration.none), |
|||
textAlign: TextAlign.center)); |
|||
widgets.AddRange(this.buildInputs(true)); |
|||
|
|||
return new Container( |
|||
padding: EdgeInsets.all(12), |
|||
child: new SingleChildScrollView(child: new Column( |
|||
crossAxisAlignment: CrossAxisAlignment.stretch, |
|||
children: widgets))); |
|||
} |
|||
} |
|||
|
|||
public class EditStateProvider : StatefulWidget |
|||
{ |
|||
public delegate EditableText EditableBuilder(BuildContext context, |
|||
TextEditingController controller, FocusNode focusNode); |
|||
|
|||
public readonly EditableBuilder builder; |
|||
|
|||
public EditStateProvider(Key key = null, EditableBuilder builder = null) : base(key) |
|||
{ |
|||
D.assert(builder != null); |
|||
this.builder = builder; |
|||
} |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new _EditStateProviderState(); |
|||
} |
|||
} |
|||
|
|||
class _EditStateProviderState : State<EditStateProvider> |
|||
{ |
|||
TextEditingController _controller; |
|||
FocusNode _focusNode; |
|||
|
|||
public override void initState() |
|||
{ |
|||
base.initState(); |
|||
this._focusNode = new FocusNode(); |
|||
this._controller = new TextEditingController(""); |
|||
} |
|||
|
|||
|
|||
public override void dispose() |
|||
{ |
|||
this._focusNode.dispose(); |
|||
base.dispose(); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return this.widget.builder(context, this._controller, this._focusNode); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: aadc2d983f1b0564688e35a7d4933599 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using uiwidgets; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
using Texture = Unity.UIWidgets.widgets.Texture; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample |
|||
{ |
|||
public class ToDoAppSample : UIWidgetsSamplePanel |
|||
{ |
|||
protected override void main() |
|||
{ |
|||
ui_.runApp( |
|||
new WidgetsApp( |
|||
home: new ToDoListApp(), |
|||
pageRouteBuilder: this.pageRouteBuilder) |
|||
); |
|||
} |
|||
|
|||
protected new void OnEnable() |
|||
{ |
|||
base.OnEnable(); |
|||
} |
|||
|
|||
public class ToDoListApp : StatefulWidget |
|||
{ |
|||
public ToDoListApp(Key key = null) : base(key) |
|||
{ |
|||
} |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new _ToDoListAppState(); |
|||
} |
|||
} |
|||
|
|||
public class CustomButton : StatelessWidget |
|||
{ |
|||
public CustomButton( |
|||
Key key = null, |
|||
GestureTapCallback onPressed = null, |
|||
EdgeInsets padding = null, |
|||
Color backgroundColor = null, |
|||
Widget child = null |
|||
) : base(key: key) |
|||
{ |
|||
this.onPressed = onPressed; |
|||
this.padding = padding ?? EdgeInsets.all(8.0f); |
|||
this.backgroundColor = backgroundColor ?? Colors.transparent; |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly GestureTapCallback onPressed; |
|||
public readonly EdgeInsets padding; |
|||
public readonly Widget child; |
|||
public readonly Color backgroundColor; |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new GestureDetector( |
|||
onTap: this.onPressed, |
|||
child: new Container( |
|||
padding: this.padding, |
|||
color: this.backgroundColor, |
|||
child: this.child |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _ToDoListAppState : State<ToDoListApp> |
|||
{ |
|||
public class ToDoItem |
|||
{ |
|||
public int id; |
|||
public string content; |
|||
} |
|||
|
|||
List<ToDoItem> items = new List<ToDoItem>(); |
|||
int nextId = 0; |
|||
TextEditingController controller = new TextEditingController(""); |
|||
FocusNode _focusNode; |
|||
|
|||
public override void initState() |
|||
{ |
|||
base.initState(); |
|||
this._focusNode = new FocusNode(); |
|||
} |
|||
|
|||
public override void dispose() |
|||
{ |
|||
this._focusNode.dispose(); |
|||
base.dispose(); |
|||
} |
|||
|
|||
Widget title() |
|||
{ |
|||
return new Text("ToDo App", textAlign: TextAlign.center, |
|||
style: new TextStyle(fontSize: 30, fontWeight: FontWeight.w700)); |
|||
} |
|||
|
|||
Widget textInput() |
|||
{ |
|||
return new Container( |
|||
child: new Row( |
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|||
children: new List<Widget>( |
|||
) |
|||
{ |
|||
new Container( |
|||
width: 300, |
|||
decoration: new BoxDecoration(border: Border.all(new Color(0xFF000000), 1)), |
|||
padding: EdgeInsets.fromLTRB(8, 0, 8, 0), |
|||
child: new EditableText(maxLines: 1, |
|||
controller: this.controller, |
|||
onSubmitted: (text) => |
|||
{ |
|||
this.controller.clear(); |
|||
this._addItem(text); |
|||
}, |
|||
selectionControls: MaterialUtils.materialTextSelectionControls, |
|||
backgroundCursorColor: Colors.red, |
|||
autofocus: true, |
|||
focusNode: new FocusNode(), |
|||
style: new TextStyle( |
|||
fontSize: 18, |
|||
height: 1.5f, |
|||
color: new Color(0xFF1389FD) |
|||
), |
|||
selectionColor: Color.fromARGB(255, 255, 0, 0), |
|||
cursorColor: Color.fromARGB(255, 0, 0, 0)) |
|||
), |
|||
|
|||
new CustomButton(backgroundColor: Color.fromARGB(255, 0, 204, 204), |
|||
padding: EdgeInsets.all(10), |
|||
child: new Text("Add", style: new TextStyle( |
|||
fontSize: 20, color: Color.fromARGB(255, 255, 255, 255), fontWeight: FontWeight.w700 |
|||
)), onPressed: () => { this._addItem(); }) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
|
|||
void _addItem(string text = null) |
|||
{ |
|||
this.setState(() => |
|||
{ |
|||
text = text ?? this.controller.text; |
|||
if (text != "") |
|||
{ |
|||
this.items.Add(new ToDoItem() |
|||
{id = this.nextId++, content = text}); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
Widget contents() |
|||
{ |
|||
var children = this.items.Select((item) => |
|||
{ |
|||
return (Widget) new Text( |
|||
item.content, style: new TextStyle( |
|||
fontSize: 18, |
|||
height: 1.5f |
|||
) |
|||
); |
|||
}); |
|||
return new Flexible( |
|||
child: new ListView( |
|||
physics: new AlwaysScrollableScrollPhysics(), |
|||
children: children.ToList() |
|||
) |
|||
); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
var container = new Container( |
|||
padding: EdgeInsets.all(10), |
|||
decoration: new BoxDecoration(color: new Color(0x7F000000), |
|||
border: Border.all(color: Color.fromARGB(255, 255, 0, 0), width: 5), |
|||
borderRadius: BorderRadius.all(2)), |
|||
child: new Column( |
|||
crossAxisAlignment: CrossAxisAlignment.stretch, |
|||
children: new List<Widget> |
|||
{ |
|||
this.title(), |
|||
this.textInput(), |
|||
// textInput(),
|
|||
this.contents(), |
|||
// this.videoTexture(),
|
|||
} |
|||
) |
|||
); |
|||
return container; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class CustomButton : StatelessWidget |
|||
{ |
|||
public CustomButton( |
|||
Key key = null, |
|||
GestureTapCallback onPressed = null, |
|||
EdgeInsets padding = null, |
|||
Color backgroundColor = null, |
|||
Widget child = null |
|||
) : base(key: key) |
|||
{ |
|||
this.onPressed = onPressed; |
|||
this.padding = padding ?? EdgeInsets.all(8.0f); |
|||
this.backgroundColor = backgroundColor ?? Colors.transparent; |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly GestureTapCallback onPressed; |
|||
public readonly EdgeInsets padding; |
|||
public readonly Widget child; |
|||
public readonly Color backgroundColor; |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new GestureDetector( |
|||
onTap: this.onPressed, |
|||
child: new Container( |
|||
padding: this.padding, |
|||
color: this.backgroundColor, |
|||
child: this.child |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.engine; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class UIWidgetsSamplePanel: UIWidgetsPanel { |
|||
|
|||
protected virtual PageRouteFactory pageRouteBuilder { |
|||
get { |
|||
return (RouteSettings settings, WidgetBuilder builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (BuildContext context, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) => builder(context) |
|||
); |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue