using System.Collections.Generic; using uiwidgets; using Unity.UIWidgets.foundation; using Unity.UIWidgets.material; using Unity.UIWidgets.painting; using Unity.UIWidgets.ui; using Unity.UIWidgets.widgets; using TextStyle = Unity.UIWidgets.painting.TextStyle; namespace UIWidgetsSample.RaycastableScene { public class PickListItem { public string itemName; public bool active; public string showName; public PickListItem(string itemName, bool active = true, string showName = null) { this.itemName = itemName; this.active = active; this.showName = showName ?? itemName; } } public class LeftUIPanel : StatefulWidget { public LeftUIPanel(Key key = null, List itemNames = null) : base(key: key) { this.itemNames = itemNames ?? new List(); } public readonly List itemNames; public override State createState() { return new LeftUIPanelState(); } } public class LeftUIPanelState : State { readonly TextEditingController controller = new TextEditingController(); public override Widget build(BuildContext context) { return new Column( children: new List { buildSearchBar(), buildItemList() } ); } public override void initState() { base.initState(); _searchResult.AddRange(widget.itemNames); } private readonly List _searchResult = new List(); private Widget buildSearchBar() { return new Container( color: Colors.lightBlue.withAlpha(125), child: new Padding( padding: EdgeInsets.all(1.0f), child: new Card( child: new Row( children: new List{ new Padding(padding: EdgeInsets.only(left: 2f)), new Icon(Icons.search, size: 14f), new Flexible(child: new TextField( controller: controller, style: new TextStyle(fontSize: 8f), decoration: new InputDecoration( hintText: "Search", border: InputBorder.none, contentPadding: EdgeInsets.all(4), isDense: true), onChanged: onSearchTextChanged )), new GestureDetector( child: new Icon(Icons.cancel, size: 10f), onTap: () => { controller.clear(); onSearchTextChanged(""); } ), new Padding(padding: EdgeInsets.only(right: 2f)) })))); } private Widget buildItemList() { return new Expanded( child: _searchResult.Count != 0 ? (Widget) ListView.builder(itemCount: _searchResult.Count, itemBuilder: (build_context, index) => { return new Container( child: new Padding( padding: EdgeInsets.only(left: 4.0f, right: 4f), child: new Card( shape:new RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(2.0f)) ), margin: EdgeInsets.all(1), child: new Row( children: new List { new Padding(padding: EdgeInsets.only(left: 2f)), new Checkbox(value: _searchResult[index].active, onChanged: (value) => { if (value == null) { return; } setState(() => { _searchResult[index].active = value.Value; }); }), new Text(_searchResult[index].showName, style: new TextStyle(fontSize: 8f)) } ) ))); }) : new Center( child: new Text("No Available Item", style: new TextStyle(fontSize: 8f)) ) ); } private void onSearchTextChanged(string text) { _searchResult.Clear(); if (text.isEmpty()) { _searchResult.AddRange(widget.itemNames); } else { foreach (var item in widget.itemNames) { if (item.showName.StartsWith(text)) { _searchResult.Add(item); } } } setState(() => {}); } } }