예제 #1
0
        List <Widget> _createTiles()
        {
            MaterialLocalizations localizations = MaterialLocalizations.of(this.context);

            D.assert(localizations != null);
            List <Widget> children = new List <Widget> {
            };

            switch (this.widget.type)
            {
            case BottomNavigationBarType.fix:
                ThemeData themeData = Theme.of(this.context);
                TextTheme textTheme = themeData.textTheme;
                Color     themeColor;
                switch (themeData.brightness)
                {
                case Brightness.light:
                    themeColor = themeData.primaryColor;
                    break;

                case Brightness.dark:
                    themeColor = themeData.accentColor;
                    break;

                default:
                    throw new Exception("Unknown brightness: " + themeData.brightness);
                }

                ColorTween colorTween = new ColorTween(
                    begin: textTheme.caption.color,
                    end: this.widget.fixedColor ?? themeColor
                    );
                for (int i = 0; i < this.widget.items.Count; i += 1)
                {
                    int index = i;
                    children.Add(
                        new _BottomNavigationTile(this.widget.type, this.widget.items[i], this._animations[i],
                                                  this.widget.iconSize,
                                                  onTap: () => {
                        if (this.widget.onTap != null)
                        {
                            this.widget.onTap(index);
                        }
                    },
                                                  colorTween: colorTween,
                                                  selected: i == this.widget.currentIndex,
                                                  indexLabel: localizations.tabLabel(tabIndex: i + 1,
                                                                                     tabCount: this.widget.items.Count)
                                                  )
                        );
                }

                break;

            case BottomNavigationBarType.shifting:
                for (int i = 0; i < this.widget.items.Count; i += 1)
                {
                    int index = i;
                    children.Add(
                        new _BottomNavigationTile(this.widget.type, this.widget.items[i], this._animations[i],
                                                  this.widget.iconSize,
                                                  onTap: () => {
                        if (this.widget.onTap != null)
                        {
                            this.widget.onTap(index);
                        }
                    },
                                                  flex:
                                                  this._evaluateFlex(this._animations[i]),
                                                  selected: i == this.widget.currentIndex,
                                                  indexLabel: localizations.tabLabel(tabIndex: i + 1,
                                                                                     tabCount: this.widget.items.Count)
                                                  )
                        );
                }

                break;
            }

            return(children);
        }
        List <Widget> _createTiles()
        {
            MaterialLocalizations localizations = MaterialLocalizations.of(this.context);

            D.assert(localizations != null);
            ThemeData themeData = Theme.of(this.context);
            Color     themeColor;

            switch (themeData.brightness)
            {
            case Brightness.light:
                themeColor = themeData.primaryColor;
                break;

            case Brightness.dark:
                themeColor = themeData.accentColor;
                break;

            default:
                throw new Exception("Unknown brightness: " + themeData.brightness);
            }

            ColorTween colorTween;

            switch (this.widget.type)
            {
            case BottomNavigationBarType.fix:
                colorTween = new ColorTween(
                    begin: this.widget.unselectedItemColor ?? themeData.textTheme.caption.color,
                    end: this.widget.selectedItemColor ?? this.widget.fixedColor ?? themeColor
                    );
                break;

            case BottomNavigationBarType.shifting:
                colorTween = new ColorTween(
                    begin: this.widget.unselectedItemColor ?? Colors.white,
                    end: this.widget.selectedItemColor ?? Colors.white
                    );
                break;

            default:
                throw new UIWidgetsError($"Unknown bottom navigation bar type: {this.widget.type}");
            }

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

            for (int i = 0; i < this.widget.items.Count; i++)
            {
                int index = i;
                tiles.Add(new _BottomNavigationTile(
                              this.widget.type,
                              this.widget.items[i],
                              this._animations[i],
                              this.widget.iconSize,
                              selectedFontSize: this.widget.selectedFontSize,
                              unselectedFontSize: this.widget.unselectedFontSize,
                              onTap: () => {
                    if (this.widget.onTap != null)
                    {
                        this.widget.onTap(index);
                    }
                },
                              colorTween: colorTween,
                              flex: this._evaluateFlex(this._animations[i]),
                              selected: i == this.widget.currentIndex,
                              showSelectedLabels: this.widget.showSelectedLabels,
                              showUnselectedLabels: this.widget.showUnselectedLabels,
                              indexLabel: localizations.tabLabel(tabIndex: i + 1, tabCount: this.widget.items.Count)
                              ));
            }

            return(tiles);
        }
예제 #3
0
        public override Widget build(BuildContext context)
        {
            ThemeData theme = Theme.of(context);
            NavigationRailThemeData navigationRailTheme = NavigationRailTheme.of(context);
            MaterialLocalizations   localizations       = MaterialLocalizations.of(context);

            Color backgroundColor =
                widget.backgroundColor ?? navigationRailTheme.backgroundColor ?? theme.colorScheme.surface;
            float         elevation                  = widget.elevation ?? navigationRailTheme.elevation ?? 0;
            float         minWidth                   = widget.minWidth ?? material_._minRailWidth;
            float         minExtendedWidth           = widget.minExtendedWidth ?? material_._minExtendedRailWidth;
            Color         baseSelectedColor          = theme.colorScheme.primary;
            Color         baseColor                  = theme.colorScheme.onSurface.withOpacity(0.64f);
            IconThemeData defaultUnselectedIconTheme =
                widget.unselectedIconTheme ?? navigationRailTheme.unselectedIconTheme;
            IconThemeData unselectedIconTheme = new IconThemeData(
                size: defaultUnselectedIconTheme?.size ?? 24.0f,
                color: defaultUnselectedIconTheme?.color ?? theme.colorScheme.onSurface,
                opacity: defaultUnselectedIconTheme?.opacity ?? 1.0f
                );
            IconThemeData defaultSelectedIconTheme = widget.selectedIconTheme ?? navigationRailTheme.selectedIconTheme;
            IconThemeData selectedIconTheme        = new IconThemeData(
                size: defaultSelectedIconTheme?.size ?? 24.0f,
                color: defaultSelectedIconTheme?.color ?? theme.colorScheme.primary,
                opacity: defaultSelectedIconTheme?.opacity ?? 0.64f
                );
            TextStyle unselectedLabelTextStyle = theme.textTheme.bodyText1.copyWith(color: baseColor)
                                                 .merge(widget.unselectedLabelTextStyle ?? navigationRailTheme.unselectedLabelTextStyle);
            TextStyle selectedLabelTextStyle = theme.textTheme.bodyText1.copyWith(color: baseSelectedColor)
                                               .merge(widget.selectedLabelTextStyle ?? navigationRailTheme.selectedLabelTextStyle);
            float groupAlignment = widget.groupAlignment ?? navigationRailTheme.groupAlignment ?? -1.0f;
            NavigationRailLabelType labelType =
                widget.labelType ?? navigationRailTheme.labelType ?? NavigationRailLabelType.none;

            var materialChildren = new List <Widget>();

            materialChildren.Add(material_._verticalSpacer);

            if (widget.leading != null)
            {
                materialChildren.AddRange(new List <Widget>()
                {
                    new ConstrainedBox(
                        constraints: new BoxConstraints(
                            minWidth: MathUtils.lerpNullableFloat(minWidth, minExtendedWidth, _extendedAnimation.value)
                            ),
                        child: widget.leading
                        ),
                    material_._verticalSpacer,
                });
            }

            var alignChildren = new List <Widget>();

            for (int i = 0; i < widget.destinations.Count; i += 1)
            {
                alignChildren.Add(new _RailDestination(
                                      minWidth: minWidth,
                                      minExtendedWidth: minExtendedWidth,
                                      extendedTransitionAnimation: _extendedAnimation,
                                      selected: widget.selectedIndex == i,
                                      icon: widget.selectedIndex == i ? widget.destinations[i].selectedIcon : widget.destinations[i].icon,
                                      label: widget.destinations[i].label,
                                      destinationAnimation: _destinationAnimations[i],
                                      labelType: labelType,
                                      iconTheme: widget.selectedIndex == i ? selectedIconTheme : unselectedIconTheme,
                                      labelTextStyle: widget.selectedIndex == i ? selectedLabelTextStyle : unselectedLabelTextStyle,
                                      onTap: () => { widget.onDestinationSelected(i); },
                                      indexLabel: localizations.tabLabel(
                                          tabIndex: i + 1,
                                          tabCount: widget.destinations.Count
                                          )
                                      ));
            }

            if (widget.trailing != null)
            {
                alignChildren.Add(new ConstrainedBox(
                                      constraints: new BoxConstraints(
                                          minWidth: MathUtils.lerpNullableFloat(minWidth, minExtendedWidth, _extendedAnimation.value)
                                          ),
                                      child: widget.trailing
                                      ));
            }

            materialChildren.Add(new Expanded(
                                     child: new Align(
                                         alignment: new Alignment(0, groupAlignment),
                                         child: new Column(
                                             mainAxisSize: MainAxisSize.min,
                                             children: alignChildren
                                             )
                                         )
                                     ));

            return(new _ExtendedNavigationRailAnimation(
                       animation: _extendedAnimation,
                       child: new Material(
                           elevation: elevation,
                           color: backgroundColor,
                           child: new Column(
                               children: materialChildren
                               )
                           )
                       ));
        }