Esempio n. 1
0
        public static NavigationRailThemeData of(BuildContext context)
        {
            NavigationRailTheme navigationRailTheme =
                context.dependOnInheritedWidgetOfExactType <NavigationRailTheme>();

            return(navigationRailTheme?.data ?? Theme.of(context).navigationRailTheme);
        }
Esempio n. 2
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
                               )
                           )
                       ));
        }
Esempio n. 3
0
        public override Widget wrap(BuildContext context, Widget child)
        {
            NavigationRailTheme ancestorTheme = context.findAncestorWidgetOfExactType <NavigationRailTheme>();

            return(ReferenceEquals(this, ancestorTheme) ? child : new NavigationRailTheme(data: data, child: child));
        }