Ejemplo n.º 1
0
        public override Widget build(BuildContext context)
        {
            List <MergeableMaterialItem> items = new List <MergeableMaterialItem>();
            EdgeInsets kExpandedEdgeInsets     = EdgeInsets.symmetric(
                vertical: ExpansionPanelUtils._kPanelHeaderExpandedHeight -
                ExpansionPanelUtils._kPanelHeaderCollapsedHeight);

            for (int index = 0; index < this.widget.children.Count; index++)
            {
                int expandIndex = index;
                if (this._isChildExpanded(index) && index != 0 && !this._isChildExpanded(index - 1))
                {
                    items.Add(new MaterialGap(
                                  key: new _SaltedKey <BuildContext, int>(context, index * 2 - 1)));
                }

                ExpansionPanel child  = this.widget.children[index];
                Row            header = new Row(
                    children: new List <Widget> {
                    new Expanded(
                        child: new AnimatedContainer(
                            duration: this.widget.animationDuration,
                            curve: Curves.fastOutSlowIn,
                            margin: this._isChildExpanded(index) ? kExpandedEdgeInsets : EdgeInsets.zero,
                            child: new ConstrainedBox(
                                constraints: new BoxConstraints(
                                    minHeight: ExpansionPanelUtils._kPanelHeaderCollapsedHeight),
                                child: child.headerBuilder(
                                    context,
                                    this._isChildExpanded(index))
                                )
                            )
                        ),
                    new Container(
                        margin: EdgeInsets.fromLTRB(0, 0, 8, 0),
                        child: new ExpandIcon(
                            isExpanded: this._isChildExpanded(index),
                            padding: EdgeInsets.all(16.0),
                            onPressed: (bool isExpanded) => this._handlePressed(isExpanded, expandIndex)
                            )
                        )
                }
                    );

                items.Add(new MaterialSlice(
                              key: new _SaltedKey <BuildContext, int>(context, index * 2),
                              child: new Column(
                                  children: new List <Widget> {
                    header,
                    new AnimatedCrossFade(
                        firstChild: new Container(height: 0.0),
                        secondChild: child.body,
                        firstCurve: new Interval(0.0, 0.6, curve: Curves.fastOutSlowIn),
                        secondCurve: new Interval(0.4, 1.0, curve: Curves.fastOutSlowIn),
                        sizeCurve: Curves.fastOutSlowIn,
                        crossFadeState: this._isChildExpanded(index)
                                        ? CrossFadeState.showSecond
                                        : CrossFadeState.showFirst,
                        duration: this.widget.animationDuration
                        )
                }
                                  )
                              )
                          );

                if (this._isChildExpanded(index) && index != this.widget.children.Count - 1)
                {
                    items.Add(new MaterialGap(
                                  key: new _SaltedKey <BuildContext, int>(context, index * 2 + 1)));
                }
            }

            return(new MergeableMaterial(
                       hasDividers: true,
                       children: items));
        }
Ejemplo n.º 2
0
        public override Widget build(BuildContext context)
        {
            List <MergeableMaterialItem> items = new List <MergeableMaterialItem>();

            for (int i = 0; i < widget.children.Count; i++)
            {
                int expandIndex = i;
                if (_isChildExpanded(expandIndex) && expandIndex != 0 && !_isChildExpanded(expandIndex - 1))
                {
                    items.Add(new MaterialGap(
                                  key: new _SaltedKey <BuildContext, int>(context, expandIndex * 2 - 1)));
                }

                ExpansionPanel child        = widget.children[expandIndex];
                Widget         headerWidget = child.headerBuilder(
                    context,
                    _isChildExpanded(expandIndex)
                    );


                Widget expandIconContainer = new Container(
                    margin: EdgeInsetsDirectional.only(end: 8.0f),
                    child: new ExpandIcon(
                        isExpanded: _isChildExpanded(expandIndex),
                        padding: EdgeInsets.all(16.0f),
                        onPressed: !child.canTapOnHeader
                            ? (bool isExpanded) => _handlePressed(isExpanded, expandIndex)
                            : (ValueChanged <bool>)null
                        )
                    );
                Widget header = new Row(
                    children: new List <Widget> {
                    new Expanded(
                        child: new AnimatedContainer(
                            duration: widget.animationDuration,
                            curve: Curves.fastOutSlowIn,
                            margin: _isChildExpanded(expandIndex) ? widget.expandedHeaderPadding : EdgeInsets.zero,
                            child: new ConstrainedBox(
                                constraints: new BoxConstraints(
                                    minHeight: material_._kPanelHeaderCollapsedHeight),
                                child: headerWidget
                                )
                            )
                        ),
                    expandIconContainer,
                }
                    );
                if (child.canTapOnHeader)
                {
                    header = new InkWell(
                        onTap: () => _handlePressed(_isChildExpanded(expandIndex), expandIndex),
                        child: header
                        );
                }

                items.Add(new MaterialSlice(
                              key: new _SaltedKey <BuildContext, int>(context, expandIndex * 2),
                              child: new Column(
                                  children: new List <Widget> {
                    header,
                    new AnimatedCrossFade(
                        firstChild: new Container(height: 0.0f),
                        secondChild: child.body,
                        firstCurve: new Interval(0.0f, 0.6f, curve: Curves.fastOutSlowIn),
                        secondCurve: new Interval(0.4f, 1.0f, curve: Curves.fastOutSlowIn),
                        sizeCurve: Curves.fastOutSlowIn,
                        crossFadeState: _isChildExpanded(expandIndex)
                                        ? CrossFadeState.showSecond
                                        : CrossFadeState.showFirst,
                        duration: widget.animationDuration
                        )
                }
                                  )
                              )
                          );

                if (_isChildExpanded(expandIndex) && expandIndex != widget.children.Count - 1)
                {
                    items.Add(new MaterialGap(
                                  key: new _SaltedKey <BuildContext, int>(context, expandIndex * 2 + 1)));
                }
            }

            return(new MergeableMaterial(
                       hasDividers: true,
                       children: items));
        }