示例#1
0
        public override Widget build(BuildContext context)
        {
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));
            ThemeData     themeData   = Theme.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 appBarIconTheme = this.widget.iconTheme ?? themeData.primaryIconTheme;
            TextStyle     centerStyle     = this.widget.textTheme?.title ?? themeData.primaryTextTheme.title;
            TextStyle     sideStyle       = this.widget.textTheme?.body1 ?? themeData.primaryTextTheme.body1;

            if (this.widget.toolbarOpacity != 1.0f)
            {
                float opacity =
                    new Interval(0.25f, 1.0f, curve: Curves.fastOutSlowIn).transform(this.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));
                }

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

            Widget leading = this.widget.leading;

            if (leading == null && this.widget.automaticallyImplyLeading)
            {
                if (hasDrawer)
                {
                    leading = new IconButton(
                        icon: new Icon(Icons.menu),
                        onPressed: this._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 = this.widget.title;

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

            Widget actions = null;

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

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

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

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

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

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

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

            Brightness           brightness   = this.widget.brightness ?? themeData.primaryColorBrightness;
            SystemUiOverlayStyle overlayStyle = brightness == Brightness.dark
                ? SystemUiOverlayStyle.light
                : SystemUiOverlayStyle.dark;

            return(new AnnotatedRegion <SystemUiOverlayStyle>(
                       value: overlayStyle,
                       child: new Material(
                           color: this.widget.backgroundColor ?? themeData.primaryColor,
                           elevation: this.widget.elevation,
                           child: appBar
                           )));
        }
示例#2
0
        public override Widget build(BuildContext context)
        {
            ThemeData   theme       = Theme.of(context);
            ColorScheme colorScheme = theme.colorScheme;
            TextTheme   textTheme   = theme.textTheme;

            bool  isDark = colorScheme.brightness == Brightness.dark;
            Color primarySurfaceColor   = isDark ? colorScheme.surface : colorScheme.primary;
            Color onPrimarySurfaceColor = isDark ? colorScheme.onSurface : colorScheme.onPrimary;

            TextStyle helpStyle = textTheme.overline?.copyWith(
                color: onPrimarySurfaceColor
                );

            Text help = new Text(
                helpText,
                style: helpStyle,
                maxLines: 1,
                overflow: TextOverflow.ellipsis
                );

            Text title = new Text(
                titleText,
                style: titleStyle,
                maxLines: (isShort || orientation == Orientation.portrait) ? 1 : 2,
                overflow: TextOverflow.ellipsis
                );
            IconButton icon = new IconButton(
                icon: new Icon(this.icon),
                color: onPrimarySurfaceColor,
                tooltip: iconTooltip,
                onPressed: onIconPressed
                );

            switch (orientation)
            {
            case Orientation.portrait:
                return(new Column(
                           crossAxisAlignment: CrossAxisAlignment.start,
                           children: new List <Widget> {
                    new Container(
                        height: DatePickerHeaderUtils._datePickerHeaderPortraitHeight,
                        color: primarySurfaceColor,
                        padding: EdgeInsetsDirectional.only(
                            start: 24f,
                            end: 12f
                            ),
                        child: new Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: new List <Widget> {
                        new SizedBox(height: 16f),
                        new Flexible(child: help),
                        new SizedBox(height: 38),
                        new Row(
                            children: new List <Widget> {
                            new Expanded(child: title),
                            icon,
                        }
                            ),
                    }
                            )
                        )
                }
                           ));

            case Orientation.landscape:
                return(new Row(
                           crossAxisAlignment: CrossAxisAlignment.start,
                           children: new List <Widget> {
                    new Container(
                        width: DatePickerHeaderUtils._datePickerHeaderLandscapeWidth,
                        color: primarySurfaceColor,
                        child: new Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: new List <Widget> {
                        new SizedBox(height: 16),
                        new Padding(
                            padding: EdgeInsets.symmetric(
                                horizontal: DatePickerHeaderUtils._headerPaddingLandscape
                                ),
                            child: help
                            ),
                        new SizedBox(height: isShort ? 16 : 56),
                        new Padding(
                            padding: EdgeInsets.symmetric(
                                horizontal: DatePickerHeaderUtils._headerPaddingLandscape
                                ),
                            child: title
                            ),
                        new Spacer(),
                        new Padding(
                            padding: EdgeInsets.symmetric(
                                horizontal: 4
                                ),
                            child: icon
                            ),
                    }
                            )
                        ),
                }
                           ));
            }

            return(null);
        }