Exemplo n.º 1
0
 public bool Equals(AppBarTheme other)
 {
     return(other.brightness == this.brightness &&
            other.color == this.color &&
            other.elevation == this.elevation &&
            other.iconTheme == this.iconTheme &&
            other.textTheme == this.textTheme);
 }
Exemplo n.º 2
0
 public bool Equals(AppBarTheme other)
 {
     return(other.brightness == brightness &&
            other.color == color &&
            Equals(other.elevation, elevation) &&
            other.iconTheme == iconTheme &&
            other.actionsIconTheme == actionsIconTheme &&
            other.textTheme == textTheme);
 }
Exemplo n.º 3
0
 public static AppBarTheme lerp(AppBarTheme a, AppBarTheme b, float t)
 {
     return(new AppBarTheme(
                brightness: t < 0.5f ? a?.brightness : b?.brightness,
                color: Color.lerp(a?.color, b?.color, t),
                elevation: MathUtils.lerpFloat(a?.elevation ?? 0.0f, b?.elevation ?? 0.0f, t),
                iconTheme: IconThemeData.lerp(a?.iconTheme, b?.iconTheme, t),
                textTheme: TextTheme.lerp(a?.textTheme, b?.textTheme, t)
                ));
 }
Exemplo n.º 4
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterialLocalizations(context));
            ThemeData     theme       = Theme.of(context);
            AppBarTheme   appBarTheme = AppBarTheme.of(context);
            ScaffoldState scaffold    = Scaffold.of(context, nullOk: true);
            ModalRoute    parentRoute = ModalRoute.of(context);

            bool hasDrawer      = scaffold?.hasDrawer ?? false;
            bool hasEndDrawer   = scaffold?.hasEndDrawer ?? false;
            bool canPop         = parentRoute?.canPop ?? false;
            bool useCloseButton = parentRoute is PageRoute && ((PageRoute)parentRoute).fullscreenDialog;

            IconThemeData overallIconTheme = widget.iconTheme
                                             ?? appBarTheme.iconTheme
                                             ?? theme.primaryIconTheme;
            IconThemeData actionsIconTheme = widget.actionsIconTheme
                                             ?? appBarTheme.actionsIconTheme
                                             ?? overallIconTheme;
            TextStyle centerStyle = widget.textTheme?.headline6
                                    ?? appBarTheme.textTheme?.headline6
                                    ?? theme.primaryTextTheme.headline6;
            TextStyle sideStyle = widget.textTheme?.bodyText2
                                  ?? appBarTheme.textTheme?.bodyText2
                                  ?? theme.primaryTextTheme.bodyText2;

            if (widget.toolbarOpacity != 1.0f)
            {
                float opacity =
                    new Interval(0.25f, 1.0f, curve: Curves.fastOutSlowIn).transform(widget.toolbarOpacity);
                if (centerStyle?.color != null)
                {
                    centerStyle = centerStyle.copyWith(color: centerStyle.color.withOpacity(opacity));
                }

                if (sideStyle?.color != null)
                {
                    sideStyle = sideStyle.copyWith(color: sideStyle.color.withOpacity(opacity));
                }

                overallIconTheme = overallIconTheme.copyWith(
                    opacity: opacity * (overallIconTheme.opacity ?? 1.0f)
                    );
                actionsIconTheme = actionsIconTheme.copyWith(
                    opacity: opacity * (actionsIconTheme.opacity ?? 1.0f)
                    );
            }

            Widget leading = widget.leading;

            if (leading == null && widget.automaticallyImplyLeading)
            {
                if (hasDrawer)
                {
                    leading = new IconButton(
                        icon: new Icon(Icons.menu),
                        onPressed: _handleDrawerButton,
                        tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip);
                }
                else
                {
                    if (canPop)
                    {
                        leading = useCloseButton ? (Widget) new CloseButton() : new BackButton();
                    }
                }
            }

            if (leading != null)
            {
                leading = new ConstrainedBox(
                    constraints: BoxConstraints.tightFor(width: AppBarUtils._kLeadingWidth),
                    child: leading);
            }

            Widget title = widget.title;

            if (title != null)
            {
                bool namesRoute;

                switch (theme.platform)
                {
                case RuntimePlatform.Android:
                case RuntimePlatform.LinuxEditor:
                case RuntimePlatform.LinuxPlayer:
                case RuntimePlatform.WindowsEditor:
                case RuntimePlatform.WindowsPlayer:
                    namesRoute = true;
                    break;

                case RuntimePlatform.IPhonePlayer:
                case RuntimePlatform.OSXEditor:
                case RuntimePlatform.OSXPlayer:
                    break;

                default:
                    break;
                }

                title = new _AppBarTitleBox(child: title);

                title = new DefaultTextStyle(
                    style: centerStyle,
                    softWrap: false,
                    overflow: TextOverflow.ellipsis,
                    child: title
                    );
            }

            Widget actions = null;

            if (widget.actions != null && widget.actions.isNotEmpty())
            {
                actions = new Row(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: widget.actions);
            }
            else if (hasEndDrawer)
            {
                actions = new IconButton(
                    icon: new Icon(Icons.menu),
                    onPressed: _handleDrawerButtonEnd,
                    tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip);
            }

            if (actions != null)
            {
                actions = IconTheme.merge(
                    data: actionsIconTheme,
                    child: actions
                    );
            }

            Widget toolbar = new NavigationToolbar(
                leading: leading,
                middle: title,
                trailing: actions,
                centerMiddle: widget._getEffectiveCenterTitle(theme).Value,
                middleSpacing: widget.titleSpacing);

            Widget appBar = new ClipRect(
                child: new CustomSingleChildLayout(
                    layoutDelegate: new _ToolbarContainerLayout(),
                    child: IconTheme.merge(
                        data: overallIconTheme,
                        child: new DefaultTextStyle(
                            style: sideStyle,
                            child: toolbar)
                        )
                    )
                );

            if (widget.bottom != null)
            {
                appBar = new Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: new List <Widget> {
                    new Flexible(
                        child: new ConstrainedBox(
                            constraints: new BoxConstraints(maxHeight: material_.kToolbarHeight),
                            child: appBar
                            )
                        ),
                    foundation_.FloatEqual(widget.bottomOpacity, 1.0f)
                            ? (Widget)widget.bottom
                            : new Opacity(
                        opacity: new Interval(0.25f, 1.0f, curve: Curves.fastOutSlowIn).transform(widget
                                                                                                  .bottomOpacity),
                        child: widget.bottom
                        )
                }
                    );
            }

            if (widget.primary)
            {
                appBar = new SafeArea(
                    bottom: false,
                    top: true,
                    child: appBar);
            }

            appBar = new Align(
                alignment: Alignment.topCenter,
                child: appBar);

            if (widget.flexibleSpace != null)
            {
                appBar = new Stack(
                    fit: StackFit.passthrough,
                    children: new List <Widget> {
                    widget.flexibleSpace,
                    appBar
                }
                    );
            }

            Brightness brightness = widget.brightness
                                    ?? appBarTheme.brightness
                                    ?? theme.primaryColorBrightness;
            SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark
                ? SystemUiOverlayStyle.light
                : SystemUiOverlayStyle.dark;

            return(new AnnotatedRegion <SystemUiOverlayStyle>(
                       value: overlayStyle,
                       child: new Material(
                           color: widget.backgroundColor
                           ?? appBarTheme.color
                           ?? theme.primaryColor,
                           elevation: widget.elevation
                           ?? appBarTheme.elevation
                           ?? _defaultElevation,
                           shape: widget.shape,
                           child: appBar
                           )));
        }