Пример #1
0
        public override Widget build(BuildContext context)
        {
            List <Widget> chips = this._materials.Select <string, Widget>((string name) => {
                return(new Chip(
                           key: Key.key(name),
                           backgroundColor: this._nameToColor(name),
                           label: new Text(this._capitalize(name)),
                           onDeleted: () => { this.setState(() => { this._removeMaterial(name); }); }
                           ));
            }).ToList();

            List <Widget> inputChips = this._tools.Select <string, Widget>((string name) => {
                return(new InputChip(
                           key: ValueKey <string> .key(name),
                           avatar: new CircleAvatar(
                               backgroundImage: this._nameToAvatar(name)
                               ),
                           label: new Text(this._capitalize(name)),
                           onDeleted: () => { this.setState(() => { this._removeTool(name); }); }));
            }).ToList();

            List <Widget> choiceChips = this._materials.Select <string, Widget>((string name) => {
                return(new ChoiceChip(
                           key: ValueKey <string> .key(name),
                           backgroundColor: this._nameToColor(name),
                           label: new Text(this._capitalize(name)),
                           selected: this._selectedMaterial == name,
                           onSelected: (bool value) => {
                    this.setState(() => { this._selectedMaterial = value ? name : ""; });
                }
                           ));
            }).ToList();

            List <Widget> filterChips = ChipDemoUtils._defaultTools.Select <string, Widget>((string name) => {
                return(new FilterChip(
                           key: ValueKey <string> .key(name),
                           label: new Text(this._capitalize(name)),
                           selected: this._tools.Contains(name) ? this._selectedTools.Contains(name) : false,
                           onSelected: !this._tools.Contains(name)
                        ? (ValueChanged <bool>)null
                        : (bool value) => {
                    this.setState(() => {
                        if (!value)
                        {
                            this._selectedTools.Remove(name);
                        }
                        else
                        {
                            this._selectedTools.Add(name);
                        }
                    });
                }
                           ));
            }).ToList();

            HashSet <string> allowedActions = new HashSet <string>(new List <string> {
            });

            if (this._selectedMaterial != null && this._selectedMaterial.isNotEmpty())
            {
                foreach (string tool in this._selectedTools)
                {
                    allowedActions.UnionWith(ChipDemoUtils._toolActions[tool]);
                }

                allowedActions =
                    new HashSet <string>(
                        allowedActions.Intersect(ChipDemoUtils._materialActions[this._selectedMaterial]));
            }

            List <Widget> actionChips = allowedActions.Select <string, Widget>((string name) => {
                return(new ActionChip(
                           label: new Text(this._capitalize(name)),
                           onPressed: () => { this.setState(() => { this._selectedAction = name; }); }
                           ));
            }).ToList();

            ThemeData     theme = Theme.of(context);
            List <Widget> tiles = new List <Widget> {
                new SizedBox(height: 8.0f, width: 0.0f),
                new _ChipsTile(label: "Available Materials (Chip)", children: chips),
                new _ChipsTile(label: "Available Tools (InputChip)", children: inputChips),
                new _ChipsTile(label: "Choose a Material (ChoiceChip)", children: choiceChips),
                new _ChipsTile(label: "Choose Tools (FilterChip)", children: filterChips),
                new _ChipsTile(label: "Perform Allowed Action (ActionChip)", children: actionChips),
                new Divider(),
                new Padding(
                    padding: EdgeInsets.all(8.0f),
                    child: new Center(
                        child: new Text(this._createResult(),
                                        style: theme.textTheme.title
                                        )
                        )
                    )
            };

            return(new Scaffold(
                       appBar: new AppBar(
                           title: new Text("Chips"),
                           actions: new List <Widget> {
                new MaterialDemoDocumentationButton(ChipDemo.routeName),
                new IconButton(
                    onPressed: () => {
                    this.setState(() => { this._showShapeBorder = !this._showShapeBorder; });
                },
                    icon: new Icon(Icons.vignette)
                    )
            }
                           ),
                       body: new ChipTheme(
                           data: this._showShapeBorder
                        ? theme.chipTheme.copyWith(
                               shape: new BeveledRectangleBorder(
                                   side: new BorderSide(width: 0.66f, style: BorderStyle.solid, color: Colors.grey),
                                   borderRadius: BorderRadius.circular(10.0f)
                                   ))
                        : theme.chipTheme,
                           child: new ListView(children: tiles)
                           ),
                       floatingActionButton: new FloatingActionButton(
                           onPressed: () => this.setState(this._reset),
                           child: new Icon(Icons.refresh)
                           )
                       ));
        }