示例#1
0
        public override bool updateShouldNotify(InheritedWidget oldWidget)
        {
            FlexibleSpaceBarSettings _oldWidget = (FlexibleSpaceBarSettings)oldWidget;

            return(toolbarOpacity != _oldWidget.toolbarOpacity ||
                   minExtent != _oldWidget.minExtent ||
                   maxExtent != _oldWidget.maxExtent ||
                   currentExtent != _oldWidget.currentExtent);
        }
示例#2
0
        float?_getCollapsePadding(float t, FlexibleSpaceBarSettings settings)
        {
            switch (widget.collapseMode)
            {
            case CollapseMode.pin:
                return(-(settings.maxExtent.Value - settings.currentExtent.Value));

            case CollapseMode.none:
                return(0.0f);

            case CollapseMode.parallax:
                float deltaExtent = settings.maxExtent.Value - settings.minExtent.Value;
                return(-new FloatTween(begin: 0.0f, end: deltaExtent / 4.0f).lerp(t));
            }

            return(null);
        }
示例#3
0
        public override Widget build(BuildContext context)
        {
            return(new LayoutBuilder(
                       builder: (BuildContext _context, BoxConstraints constraints) => {
                FlexibleSpaceBarSettings settings =
                    _context.dependOnInheritedWidgetOfExactType <FlexibleSpaceBarSettings>();
                D.assert(settings != null,
                         () =>
                         "A FlexibleSpaceBar must be wrapped in the widget returned by FlexibleSpaceBar.createSettings().");

                List <Widget> children = new List <Widget>();
                float deltaExtent = settings.maxExtent.Value - settings.minExtent.Value;

                float t = (1.0f - (settings.currentExtent.Value - settings.minExtent.Value) / deltaExtent)
                          .clamp(0.0f, 1.0f);

                if (widget.background != null)
                {
                    float fadeStart = Mathf.Max(0.0f, 1.0f - material_.kToolbarHeight / deltaExtent);
                    float fadeEnd = 1.0f;
                    D.assert(fadeStart <= fadeEnd);

                    float opacity = 1.0f - new Interval(fadeStart, fadeEnd).transform(t);
                    if (opacity > 0.0f)
                    {
                        float height = settings.maxExtent ?? 0;

                        if (widget.stretchModes.Contains(StretchMode.zoomBackground) &&
                            constraints.maxHeight > height)
                        {
                            height = constraints.maxHeight;
                        }

                        children.Add(new Positioned(
                                         top: _getCollapsePadding(t, settings),
                                         left: 0.0f,
                                         right: 0.0f,
                                         height: height,
                                         child: new Opacity(
                                             opacity: opacity,
                                             child: widget.background)
                                         )
                                     );

                        if (widget.stretchModes.Contains(StretchMode.blurBackground) &&
                            constraints.maxHeight > settings.maxExtent)
                        {
                            float blurAmount = (constraints.maxHeight - settings.maxExtent) / 10 ?? 0;
                            children.Add(Positioned.fill(
                                             child: new BackdropFilter(
                                                 child: new Container(
                                                     color: Colors.transparent
                                                     ),
                                                 filter: ui.ImageFilter.blur(
                                                     sigmaX: blurAmount,
                                                     sigmaY: blurAmount
                                                     )
                                                 )
                                             ));
                        }
                    }
                }

                Widget title = null;
                if (widget.title != null)
                {
                    switch (Application.platform)
                    {
                    case RuntimePlatform.IPhonePlayer:
                        title = widget.title;
                        break;

                    default:
                        title = widget.title;
                        break;
                    }
                }

                if (widget.stretchModes.Contains(StretchMode.fadeTitle) &&
                    constraints.maxHeight > settings.maxExtent)
                {
                    float stretchOpacity =
                        1 - (((constraints.maxHeight - settings.maxExtent) / 100)?.clamp(0.0f, 1.0f) ?? 0);
                    title = new Opacity(
                        opacity: stretchOpacity,
                        child: title
                        );
                }

                ThemeData theme = Theme.of(_context);
                float toolbarOpacity = settings.toolbarOpacity.Value;
                if (toolbarOpacity > 0.0f)
                {
                    TextStyle titleStyle = theme.primaryTextTheme.title;
                    titleStyle = titleStyle.copyWith(
                        color: titleStyle.color.withOpacity(toolbarOpacity));

                    bool effectiveCenterTitle = _getEffectiveCenterTitle(theme).Value;
                    EdgeInsetsGeometry padding = widget.titlePadding ??
                                                 EdgeInsets.only(
                        left: effectiveCenterTitle ? 0.0f : 72.0f,
                        bottom: 16.0f
                        );
                    float scaleValue = new FloatTween(begin: 1.5f, end: 1.0f).lerp(t);
                    Matrix4 scaleTransform = Matrix4.diagonal3Values(scaleValue, scaleValue, 1);
                    Alignment titleAlignment = _getTitleAlignment(effectiveCenterTitle);

                    children.Add(new Container(
                                     padding: padding,
                                     child: new Transform(
                                         alignment: titleAlignment,
                                         transform: scaleTransform,
                                         child: new Align(
                                             alignment: titleAlignment,
                                             child: new DefaultTextStyle(
                                                 style: titleStyle,
                                                 child: new LayoutBuilder(
                                                     builder: (BuildContext __context, BoxConstraints _constraints) => {
                        return new Container(
                            width: _constraints.maxWidth / scaleValue,
                            alignment: titleAlignment,
                            child: title
                            );
                    }
                                                     )
                                                 )
                                             )
                                         )
                                     )
                                 );
                }

                return new ClipRect(
                    child: new Stack(
                        children: children)
                    );
            }
                       ));
        }
示例#4
0
        public override Widget build(BuildContext context)
        {
            FlexibleSpaceBarSettings settings =
                (FlexibleSpaceBarSettings)context.inheritFromWidgetOfExactType(typeof(FlexibleSpaceBarSettings));

            D.assert(settings != null,
                     () => "A FlexibleSpaceBar must be wrapped in the widget returned by FlexibleSpaceBar.createSettings().");

            List <Widget> children    = new List <Widget>();
            float         deltaExtent = settings.maxExtent.Value - settings.minExtent.Value;

            float t = (1.0f - (settings.currentExtent.Value - settings.minExtent.Value) / deltaExtent)
                      .clamp(0.0f, 1.0f);

            if (this.widget.background != null)
            {
                float fadeStart = Mathf.Max(0.0f, 1.0f - Constants.kToolbarHeight / deltaExtent);
                float fadeEnd   = 1.0f;
                D.assert(fadeStart <= fadeEnd);

                float opacity = 1.0f - new Interval(fadeStart, fadeEnd).transform(t);
                if (opacity > 0.0f)
                {
                    children.Add(new Positioned(
                                     top: this._getCollapsePadding(t, settings),
                                     left: 0.0f,
                                     right: 0.0f,
                                     height: settings.maxExtent,
                                     child: new Opacity(
                                         opacity: opacity,
                                         child: this.widget.background)
                                     )
                                 );
                }
            }

            Widget title = null;

            if (this.widget.title != null)
            {
                switch (Application.platform)
                {
                case RuntimePlatform.IPhonePlayer:
                    title = this.widget.title;
                    break;

                default:
                    title = this.widget.title;
                    break;
                }
            }

            ThemeData theme          = Theme.of(context);
            float     toolbarOpacity = settings.toolbarOpacity.Value;

            if (toolbarOpacity > 0.0f)
            {
                TextStyle titleStyle = theme.primaryTextTheme.title;
                titleStyle = titleStyle.copyWith(
                    color: titleStyle.color.withOpacity(toolbarOpacity));

                bool       effectiveCenterTitle = this._getEffectiveCenterTitle(theme).Value;
                EdgeInsets padding = this.widget.titlePadding ??
                                     EdgeInsets.only(
                    left: effectiveCenterTitle ? 0.0f : 72.0f,
                    bottom: 16.0f
                    );
                float     scaleValue     = new FloatTween(begin: 1.5f, end: 1.0f).lerp(t);
                Matrix4   scaleTransform = new Matrix4().diagonal3Values(scaleValue, scaleValue, 1);
                Alignment titleAlignment = this._getTitleAlignment(effectiveCenterTitle);

                children.Add(new Container(
                                 padding: padding,
                                 child: new Transform(
                                     alignment: titleAlignment,
                                     transform: scaleTransform,
                                     child: new Align(
                                         alignment: titleAlignment,
                                         child: new DefaultTextStyle(
                                             style: titleStyle,
                                             child: title)
                                         )
                                     )
                                 )
                             );
            }

            return(new ClipRect(
                       child: new Stack(
                           children: children)
                       ));
        }