示例#1
0
        Widget _buildYearItem(BuildContext context, int index)
        {
            ColorScheme colorScheme = Theme.of(context).colorScheme;
            TextTheme   textTheme   = Theme.of(context).textTheme;

            // Backfill the _YearPicker with disabled years if necessary.
            int         offset = _itemCount < minYears ? (int)(1.0f * (minYears - _itemCount) / 2) : 0;
            int         year = widget.firstDate.Year + index - offset;
            bool        isSelected = year == widget.selectedDate.Year;
            bool        isCurrentYear = year == widget.currentDate.Year;
            bool        isDisabled = year <widget.firstDate.Year || year> widget.lastDate.Year;
            const float decorationHeight = 36.0f;
            const float decorationWidth  = 72.0f;

            Color textColor;

            if (isSelected)
            {
                textColor = colorScheme.onPrimary;
            }
            else if (isDisabled)
            {
                textColor = colorScheme.onSurface.withOpacity(0.38f);
            }
            else if (isCurrentYear)
            {
                textColor = colorScheme.primary;
            }
            else
            {
                textColor = colorScheme.onSurface.withOpacity(0.87f);
            }

            TextStyle itemStyle = textTheme.bodyText1?.apply(color: textColor);

            BoxDecoration decoration = null;

            if (isSelected)
            {
                decoration = new BoxDecoration(
                    color: colorScheme.primary,
                    borderRadius: BorderRadius.circular(decorationHeight / 2),
                    shape: BoxShape.rectangle
                    );
            }
            else if (isCurrentYear && !isDisabled)
            {
                decoration = new BoxDecoration(
                    border: Border.all(
                        color: colorScheme.primary,
                        width: 1
                        ),
                    borderRadius: BorderRadius.circular(decorationHeight / 2),
                    shape: BoxShape.rectangle
                    );
            }

            Widget yearItem = new Center(
                child: new Container(
                    decoration: decoration,
                    height: decorationHeight,
                    width: decorationWidth,
                    child: new Center(
                        child: new Text(year.ToString(), style: itemStyle)
                        )
                    )
                );

            if (!isDisabled)
            {
                yearItem = new InkWell(
                    key: new ValueKey <int>(year),
                    onTap: () => {
                    widget.onChanged(
                        new DateTime(
                            year,
                            widget.initialDate.Month,
                            widget.initialDate.Day
                            )
                        );
                },
                    child: yearItem
                    );
            }

            return(yearItem);
        }
示例#2
0
        public override Widget build(BuildContext context)
        {
            D.assert(WidgetsD.debugCheckHasDirectionality(context));
            D.assert(material_.debugCheckHasMaterialLocalizations(context));
            D.assert(material_.debugCheckHasMaterialLocalizations(context));

            ThemeData     theme    = Theme.of(context);
            List <Widget> children = new List <Widget> {
            };

            if (widget.accountName != null)
            {
                Widget accountNameLine = new LayoutId(
                    id: _AccountDetailsLayout.accountName,
                    child: new Padding(
                        padding: EdgeInsets.symmetric(vertical: 2.0f),
                        child: new DefaultTextStyle(
                            style: theme.primaryTextTheme.bodyText1,
                            overflow: TextOverflow.ellipsis,
                            child: widget.accountName
                            )
                        )
                    );
                children.Add(accountNameLine);
            }

            if (widget.accountEmail != null)
            {
                Widget accountEmailLine = new LayoutId(
                    id: _AccountDetailsLayout.accountEmail,
                    child: new Padding(
                        padding: EdgeInsets.symmetric(vertical: 2.0f),
                        child: new DefaultTextStyle(
                            style: theme.primaryTextTheme.bodyText2,
                            overflow: TextOverflow.ellipsis,
                            child: widget.accountEmail
                            )
                        )
                    );
                children.Add(accountEmailLine);
            }

            if (widget.onTap != null)
            {
                Widget dropDownIcon = new LayoutId(
                    id: _AccountDetailsLayout.dropdownIcon,
                    child: new SizedBox(
                        height: UserAccountsDrawerHeaderUtils._kAccountDetailsHeight,
                        width: UserAccountsDrawerHeaderUtils._kAccountDetailsHeight,
                        child: new Center(
                            child: Transform.rotate(
                                angle: _animation.value * Mathf.PI,
                                child: new Icon(
                                    Icons.arrow_drop_down,
                                    color: widget.arrowColor
                                    )
                                )
                            )
                        )
                    );
                children.Add(dropDownIcon);
            }

            Widget accountDetails = new CustomMultiChildLayout(
                layoutDelegate: new _AccountDetailsLayout(
                    Directionality.of(context)),
                children: children
                );

            if (widget.onTap != null)
            {
                accountDetails = new InkWell(
                    onTap: widget.onTap == null ? (GestureTapCallback)null : () => { widget.onTap(); },
                    child: accountDetails
                    );
            }

            return(new SizedBox(
                       height: UserAccountsDrawerHeaderUtils._kAccountDetailsHeight,
                       child: accountDetails
                       ));
        }
示例#3
0
        Widget _buildDataCell(
            BuildContext context,
            EdgeInsetsGeometry padding,
            Widget label,
            bool numeric,
            bool placeholder,
            bool showEditIcon,
            VoidCallback onTap,
            VoidCallback onSelectChanged
            )
        {
            bool isLightTheme = Theme.of(context).brightness == Brightness.light;

            if (showEditIcon)
            {
                Widget icon = new Icon(Icons.edit, size: 18.0f);
                label = new Expanded(child: label);
                label = new Row(
                    textDirection: numeric ? TextDirection.rtl : (TextDirection?)null,
                    children: new List <Widget> {
                    label, icon
                }
                    );
            }

            label = new Container(
                padding: padding,
                height: dataRowHeight,
                alignment: numeric ? Alignment.centerRight : (AlignmentGeometry)AlignmentDirectional.centerStart,
                child: new DefaultTextStyle(
                    style: new TextStyle(
                        // TODO(ianh): font family should be Roboto; see https://github.com/flutter/flutter/issues/3116
                        fontSize: 13.0f,
                        color: isLightTheme
                            ? (placeholder ? Colors.black38 : Colors.black87)
                            : (placeholder ? Colors.white38 : Colors.white70)
                        ),
                    child: IconTheme.merge(
                        data: new IconThemeData(
                            color: isLightTheme ? Colors.black54 : Colors.white70
                            ),
                        child: new DropdownButtonHideUnderline(child: label)
                        )
                    )
                );
            if (onTap != null)
            {
                label = new InkWell(
                    onTap: () => onTap(),
                    child: label
                    );
            }
            else if (onSelectChanged != null)
            {
                label = new TableRowInkWell(
                    onTap: () => onSelectChanged(),
                    child: label
                    );
            }

            return(label);
        }
示例#4
0
        Widget _buildHeadingCell(
            BuildContext context       = null,
            EdgeInsetsGeometry padding = null,
            Widget label        = null,
            string tooltip      = null,
            bool?numeric        = null,
            VoidCallback onSort = null,
            bool?sorted         = null,
            bool?ascending      = null
            )
        {
            List <Widget> arrowWithPadding()
            {
                return(onSort == null
                    ? new List <Widget>()
                    : new List <
                           Widget>()
                {
                    new _SortArrow(
                        visible: sorted,
                        down: sorted ?? false ? ascending : null,
                        duration: _sortArrowAnimationDuration
                        ),

                    new SizedBox(width: _sortArrowPadding)
                });
            }

            var rowChild = new List <Widget>();

            rowChild.Add(label);
            rowChild.AddRange(arrowWithPadding());
            label = new Row(
                textDirection: numeric ?? false ? TextDirection.rtl : (TextDirection?)null,
                children: rowChild
                );
            label = new Container(
                padding: padding,
                height: headingRowHeight,
                alignment: numeric ?? false
                    ? Alignment.centerRight
                    : (AlignmentGeometry)AlignmentDirectional.centerStart,
                child: new AnimatedDefaultTextStyle(
                    style: new TextStyle(
                        fontWeight: FontWeight.w500,
                        fontSize: _headingFontSize,
                        height: Mathf.Min(1.0f, headingRowHeight / _headingFontSize),
                        color: (Theme.of(context).brightness == Brightness.light)
                            ? ((onSort != null && (sorted ?? false)) ? Colors.black87 : Colors.black54)
                            : ((onSort != null && (sorted ?? false)) ? Colors.white : Colors.white70)
                        ),
                    softWrap: false,
                    duration: _sortArrowAnimationDuration,
                    child: label
                    )
                );
            if (tooltip != null)
            {
                label = new Tooltip(
                    message: tooltip,
                    child: label
                    );
            }

            // TODO(dkwingsmt): Only wrap Inkwell if onSort != null. Blocked by
            // https://github.com/flutter/flutter/issues/51152
            label = new InkWell(
                onTap: () => onSort?.Invoke(),
                child: label
                );
            return(label);
        }
示例#5
0
        public override Widget build(BuildContext context)
        {
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));

            if (this._controller.length == 0)
            {
                return(new Container(
                           height: TabsUtils._kTabHeight + this.widget.indicatorWeight
                           ));
            }

            List <Widget> wrappedTabs = new List <Widget>();

            for (int i = 0; i < this.widget.tabs.Count; i++)
            {
                wrappedTabs.Add(new Center(
                                    heightFactor: 1.0f,
                                    child: new Padding(
                                        padding: this.widget.labelPadding ?? Constants.kTabLabelPadding,
                                        child: new KeyedSubtree(
                                            key: this._tabKeys[i],
                                            child: this.widget.tabs[i]
                                            )
                                        )
                                    )
                                );
            }

            if (this._controller != null)
            {
                int previousIndex = this._controller.previousIndex;

                if (this._controller.indexIsChanging)
                {
                    D.assert(this._currentIndex != previousIndex);
                    Animation <float> animation = new _ChangeAnimation(this._controller);
                    wrappedTabs[this._currentIndex] =
                        this._buildStyledTab(wrappedTabs[this._currentIndex], true, animation);
                    wrappedTabs[previousIndex] = this._buildStyledTab(wrappedTabs[previousIndex], false, animation);
                }
                else
                {
                    int tabIndex = this._currentIndex;
                    Animation <float> centerAnimation = new _DragAnimation(this._controller, tabIndex);
                    wrappedTabs[tabIndex] = this._buildStyledTab(wrappedTabs[tabIndex], true, centerAnimation);
                    if (this._currentIndex > 0)
                    {
                        int previousTabIndex = this._currentIndex - 1;
                        Animation <float> previousAnimation =
                            new ReverseAnimation(new _DragAnimation(this._controller, previousTabIndex));
                        wrappedTabs[previousTabIndex] =
                            this._buildStyledTab(wrappedTabs[previousTabIndex], false, previousAnimation);
                    }

                    if (this._currentIndex < this.widget.tabs.Count - 1)
                    {
                        int nextTabIndex = this._currentIndex + 1;
                        Animation <float> nextAnimation =
                            new ReverseAnimation(new _DragAnimation(this._controller, nextTabIndex));
                        wrappedTabs[nextTabIndex] =
                            this._buildStyledTab(wrappedTabs[nextTabIndex], false, nextAnimation);
                    }
                }
            }

            int tabCount = this.widget.tabs.Count;

            for (int index = 0; index < tabCount; index++)
            {
                int tabIndex = index;
                wrappedTabs[index] = new InkWell(
                    onTap: () => { this._handleTap(tabIndex); },
                    child: new Padding(
                        padding: EdgeInsets.only(bottom: this.widget.indicatorWeight),
                        child: wrappedTabs[index]
                        )
                    );
                if (!this.widget.isScrollable)
                {
                    wrappedTabs[index] = new Expanded(
                        child: wrappedTabs[index]);
                }
            }

            Widget tabBar = new CustomPaint(
                painter: this._indicatorPainter,
                child: new _TabStyle(
                    animation: Animations.kAlwaysDismissedAnimation,
                    selected: false,
                    labelColor: this.widget.labelColor,
                    unselectedLabelColor: this.widget.unselectedLabelColor,
                    labelStyle: this.widget.labelStyle,
                    unselectedLabelStyle: this.widget.unselectedLabelStyle,
                    child: new _TabLabelBar(
                        onPerformLayout: this._saveTabOffsets,
                        children: wrappedTabs
                        )
                    )
                );

            if (this.widget.isScrollable)
            {
                this._scrollController = this._scrollController ?? new _TabBarScrollController(this);
                tabBar = new SingleChildScrollView(
                    scrollDirection: Axis.horizontal,
                    controller: this._scrollController,
                    child: tabBar);
            }

            return(tabBar);
        }
示例#6
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));
        }