Пример #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
            }
                           )
                       ));
        }
        public override Widget build(BuildContext context)
        {
            ThemeData             theme         = Theme.of(context);
            ColorScheme           colorScheme   = theme.colorScheme;
            MaterialLocalizations localizations = MaterialLocalizations.of(context);
            Orientation?          orientation   = MediaQuery.of(context).orientation;
            TextTheme             textTheme     = theme.textTheme;

            float textScaleFactor = Mathf.Min(MediaQuery.of(context).textScaleFactor, 1.3f);

            string dateText = _selectedDate != null
                ? localizations.formatMediumDate(_selectedDate)
                : "Date";

            Color dateColor = colorScheme.brightness == Brightness.light
                ? colorScheme.onPrimary
                : colorScheme.onSurface;
            TextStyle dateStyle = orientation == Orientation.landscape
                ? textTheme.headline5?.copyWith(color: dateColor)
                : textTheme.headline4?.copyWith(color: dateColor);

            Widget actions = new ButtonBar(
                buttonTextTheme: ButtonTextTheme.primary,
                layoutBehavior: ButtonBarLayoutBehavior.constrained,
                children: new List <Widget> {
                new FlatButton(
                    child: new Text(widget.cancelText ?? localizations.cancelButtonLabel),
                    onPressed: _handleCancel
                    ),
                new FlatButton(
                    child: new Text(widget.confirmText ?? localizations.okButtonLabel),
                    onPressed: _handleOk
                    ),
            }
                );

            Widget   picker           = null;
            IconData entryModeIcon    = null;
            string   entryModeTooltip = null;

            switch (_entryMode)
            {
            case DatePickerEntryMode.calendar:
                picker = new CalendarDatePicker(
                    key: _calendarPickerKey,
                    initialDate: _selectedDate,
                    firstDate: widget.firstDate,
                    lastDate: widget.lastDate,
                    onDateChanged: _handleDateChanged,
                    selectableDayPredicate: widget.selectableDayPredicate,
                    initialCalendarMode: widget.initialCalendarMode
                    );
                entryModeIcon    = Icons.edit;
                entryModeTooltip = "Switch to input";
                break;

            case DatePickerEntryMode.input:
                picker = new Form(
                    key: _formKey,
                    autovalidate: _autoValidate,
                    child: new InputDatePickerFormField(
                        initialDate: _selectedDate,
                        firstDate: widget.firstDate,
                        lastDate: widget.lastDate,
                        onDateSubmitted: _handleDateChanged,
                        onDateSaved: _handleDateChanged,
                        selectableDayPredicate: widget.selectableDayPredicate,
                        errorFormatText: widget.errorFormatText,
                        errorInvalidText: widget.errorInvalidText,
                        fieldHintText: widget.fieldHintText,
                        fieldLabelText: widget.fieldLabelText,
                        autofocus: true
                        )
                    );
                entryModeIcon    = Icons.calendar_today;
                entryModeTooltip = "Switch to calendar";
                break;
            }

            Widget header = new DatePickerHeader(
                helpText: widget.helpText ?? "SELECT DATE",
                titleText: dateText,
                titleStyle: dateStyle,
                orientation: orientation,
                isShort: orientation == Orientation.landscape,
                icon: entryModeIcon,
                iconTooltip: entryModeTooltip,
                onIconPressed: _handelEntryModeToggle
                );

            Size        dialogSize  = _dialogSize(context) * textScaleFactor;
            DialogTheme dialogTheme = Theme.of(context).dialogTheme;

            return(new Dialog(
                       child: new AnimatedContainer(
                           width: dialogSize.width,
                           height: dialogSize.height,
                           duration: material_._dialogSizeAnimationDuration,
                           curve: Curves.easeIn,
                           child: new MediaQuery(
                               data: MediaQuery.of(context).copyWith(
                                   textScaleFactor: textScaleFactor
                                   ),
                               child: new Builder(builder: (BuildContext subContext) => {
                switch (orientation)
                {
                case Orientation.portrait:
                    return new Column(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: new List <Widget> {
                        header,
                        new Expanded(child: picker),
                        actions,
                    }
                        );

                case Orientation.landscape:
                    return new Row(
                        mainAxisSize: MainAxisSize.min,
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: new List <Widget> {
                        header,
                        new Flexible(
                            child: new Column(
                                mainAxisSize: MainAxisSize.min,
                                crossAxisAlignment: CrossAxisAlignment.stretch,
                                children: new List <Widget> {
                            new Expanded(child: picker),
                            actions,
                        }
                                )
                            ),
                    }
                        );
                }

                return null;
            })
                               )
                           ),
                       insetPadding: EdgeInsets.symmetric(horizontal: 16.0f, vertical: 24.0f),
                       shape: dialogTheme.shape ?? new RoundedRectangleBorder(
                           borderRadius: BorderRadius.all(Radius.circular(4.0f))
                           ),
                       clipBehavior: Clip.antiAlias
                       ));
        }