Exemplo n.º 1
0
        public override Widget build(BuildContext context)
        {
            MaterialLocalizations localizations   = MaterialLocalizations.of(context);
            ThemeData             themeData       = Theme.of(context);
            TextTheme             headerTextTheme = themeData.primaryTextTheme;
            Color dayColor  = null;
            Color yearColor = null;

            switch (themeData.primaryColorBrightness)
            {
            case Brightness.light:
                dayColor  = this.mode == DatePickerMode.day ? Colors.black87 : Colors.black54;
                yearColor = this.mode == DatePickerMode.year ? Colors.black87 : Colors.black54;
                break;

            case Brightness.dark:
                dayColor  = this.mode == DatePickerMode.day ? Colors.white : Colors.white70;
                yearColor = this.mode == DatePickerMode.year ? Colors.white : Colors.white70;
                break;
            }

            TextStyle dayStyle        = headerTextTheme.display1.copyWith(color: dayColor, height: 1.4f);
            TextStyle yearStyle       = headerTextTheme.subhead.copyWith(color: yearColor, height: 1.4f);
            Color     backgroundColor = null;

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

            case Brightness.dark:
                backgroundColor = themeData.backgroundColor;
                break;
            }

            float             width             = 0f;
            float             height            = 0f;
            EdgeInsets        padding           = null;
            MainAxisAlignment mainAxisAlignment = MainAxisAlignment.center;

            switch (this.orientation)
            {
            case Orientation.portrait:
                height            = DatePickerUtils._kDatePickerHeaderPortraitHeight;
                padding           = EdgeInsets.symmetric(horizontal: 16.0f);
                mainAxisAlignment = MainAxisAlignment.center;
                break;

            case Orientation.landscape:
                width             = DatePickerUtils._kDatePickerHeaderLandscapeWidth;
                padding           = EdgeInsets.all(8.0f);
                mainAxisAlignment = MainAxisAlignment.start;
                break;
            }

            Widget yearButton = new IgnorePointer(
                ignoring: this.mode != DatePickerMode.day,
                child: new _DateHeaderButton(
                    color: backgroundColor,
                    onTap: Feedback.wrapForTap(() => this._handleChangeMode(DatePickerMode.year), context),
                    child: new Text(localizations.formatYear(this.selectedDate), style: yearStyle)
                    )
                );
            Widget dayButton = new IgnorePointer(
                ignoring: this.mode == DatePickerMode.day,
                child: new _DateHeaderButton(
                    color: backgroundColor,
                    onTap: Feedback.wrapForTap(() => this._handleChangeMode(DatePickerMode.day), context),
                    child: new Text(localizations.formatMediumDate(this.selectedDate), style: dayStyle)
                    )
                );

            return(new Container(
                       width: width,
                       height: height,
                       padding: padding,
                       color: backgroundColor,
                       child: new Column(
                           mainAxisAlignment: mainAxisAlignment,
                           crossAxisAlignment: CrossAxisAlignment.start,
                           children: new List <Widget> {
                yearButton, dayButton
            }
                           )
                       ));
        }