using System.Collections.Generic; using System.Linq; using Unity.UIWidgets.engine; using Unity.UIWidgets.foundation; using Unity.UIWidgets.gestures; using Unity.UIWidgets.painting; using Unity.UIWidgets.rendering; using Unity.UIWidgets.ui; using Unity.UIWidgets.widgets; using TextStyle = Unity.UIWidgets.painting.TextStyle; namespace UIWidgetsSample { public class ToDoAppCanvas : WidgetCanvas { public class ToDoListApp : StatefulWidget { public ToDoListApp(Key key = null) : base(key) { } public override State createState() { return new _ToDoListAppState(); } } protected override Widget getWidget() { return new ToDoListApp(); } 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.0); this.backgroundColor = backgroundColor ?? AsScreenCanvas.CLColors.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 { public class ToDoItem { public int id; public string content; } List items = new List(); 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( ) { 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, 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.setState(() => { if (this.controller.text != "") { this.items.Add(new ToDoItem() {id = this.nextId++, content = this.controller.text}); } }); }) } ) ); } Widget contents() { var children = this.items.Select((item) => { return (Widget) new Text( item.content, style: new TextStyle( fontSize: 18, height: 1.5 ) ); }); 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 { this.title(), this.textInput(), // textInput(), this.contents(), } ) ); 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.0); this.backgroundColor = backgroundColor ?? AsScreenCanvas.CLColors.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 ) ); } } }