Пример #1
0
 internal _DayPicker(
     Key key = null,
     DateTime?currentDate              = null,
     DateTime?displayedMonth           = null,
     DateTime?firstDate                = null,
     DateTime?lastDate                 = null,
     DateTime?selectedDate             = null,
     ValueChanged <DateTime> onChanged = null,
     material_.SelectableDayPredicate selectableDayPredicate = null
     ) : base(key: key)
 {
     D.assert(currentDate != null);
     D.assert(displayedMonth != null);
     D.assert(firstDate != null);
     D.assert(lastDate != null);
     D.assert(selectedDate != null);
     D.assert(onChanged != null);
     D.assert(!(firstDate > lastDate));
     D.assert(!(selectedDate < firstDate));
     D.assert(!(selectedDate > lastDate));
     this.currentDate            = currentDate.Value;
     this.displayedMonth         = displayedMonth.Value;
     this.firstDate              = firstDate.Value;
     this.lastDate               = lastDate.Value;
     this.selectedDate           = selectedDate.Value;
     this.onChanged              = onChanged;
     this.selectableDayPredicate = selectableDayPredicate;
 }
        public _DatePickerDialog(
            Key key = null,
            DateTime?initialDate = null,
            DateTime?firstDate   = null,
            DateTime?lastDate    = null,
            DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
            material_.SelectableDayPredicate selectableDayPredicate = null,
            string cancelText  = null,
            string confirmText = null,
            string helpText    = null,
            DatePickerMode initialCalendarMode = DatePickerMode.day,
            string errorFormatText             = null,
            string errorInvalidText            = null,
            string fieldHintText  = null,
            string fieldLabelText = null
            ) : base(key: key)
        {
            D.assert(initialDate != null);
            D.assert(firstDate != null);
            D.assert(lastDate != null);

            initialDate = utils.dateOnly(initialDate.Value);
            firstDate   = utils.dateOnly(firstDate.Value);
            lastDate    = utils.dateOnly(lastDate.Value);

            D.assert(
                !lastDate.Value.isBefore(firstDate.Value),
                () => $"lastDate {lastDate} must be on or after firstDate {firstDate}."
                );
            D.assert(
                initialDate == null || !initialDate.Value.isBefore(firstDate.Value),
                () => $"initialDate {initialDate} must be on or after firstDate {firstDate}."
                );
            D.assert(
                initialDate == null || !initialDate.Value.isAfter(lastDate.Value),
                () => $"initialDate {initialDate} must be on or before lastDate {lastDate}."
                );
            D.assert(
                selectableDayPredicate == null || initialDate == null || selectableDayPredicate(initialDate.Value),
                () => $"Provided initialDate {initialDate} must satisfy provided selectableDayPredicate."
                );

            this.initialDate            = initialDate.Value;
            this.firstDate              = firstDate.Value;
            this.lastDate               = lastDate.Value;
            this.initialEntryMode       = initialEntryMode;
            this.selectableDayPredicate = selectableDayPredicate;
            this.cancelText             = cancelText;
            this.confirmText            = confirmText;
            this.helpText               = helpText;
            this.initialCalendarMode    = initialCalendarMode;
            this.errorFormatText        = errorFormatText;
            this.errorInvalidText       = errorInvalidText;
            this.fieldHintText          = fieldHintText;
            this.fieldLabelText         = fieldLabelText;
        }
Пример #3
0
        public InputDatePickerFormField(
            Key key = null,
            DateTime?initialDate = null,
            DateTime?firstDate   = null,
            DateTime?lastDate    = null,
            ValueChanged <DateTime> onDateSubmitted = null,
            ValueChanged <DateTime> onDateSaved     = null,
            material_.SelectableDayPredicate selectableDayPredicate = null,
            string errorFormatText  = null,
            string errorInvalidText = null,
            string fieldHintText    = null,
            string fieldLabelText   = null,
            bool autofocus          = false
            ) : base(key: key)
        {
            D.assert(firstDate != null);
            D.assert(lastDate != null);

            initialDate = initialDate != null?utils.dateOnly(initialDate.Value) : (DateTime?)null;

            firstDate = utils.dateOnly(firstDate.Value);
            lastDate  = utils.dateOnly(lastDate.Value);

            D.assert(
                !lastDate.Value.isBefore(firstDate.Value),
                () => $"lastDate {lastDate} must be on or after firstDate {firstDate}."
                );
            D.assert(
                initialDate == null || !initialDate.Value.isBefore(firstDate.Value),
                () => $"initialDate {initialDate} must be on or after firstDate {firstDate}."
                );
            D.assert(
                initialDate == null || !initialDate.Value.isAfter(lastDate.Value),
                () => $"initialDate {initialDate} must be on or before lastDate {lastDate}."
                );
            D.assert(
                selectableDayPredicate == null || initialDate == null || selectableDayPredicate(initialDate.Value),
                () => $"Provided initialDate {initialDate} must satisfy provided selectableDayPredicate."
                );

            this.initialDate            = initialDate;
            this.firstDate              = firstDate.Value;
            this.lastDate               = lastDate.Value;
            this.onDateSubmitted        = onDateSubmitted;
            this.onDateSaved            = onDateSaved;
            this.selectableDayPredicate = selectableDayPredicate;
            this.errorFormatText        = errorFormatText;
            this.errorInvalidText       = errorInvalidText;
            this.fieldHintText          = fieldHintText;
            this.fieldLabelText         = fieldLabelText;
            this.autofocus              = autofocus;
        }
        public CalendarDatePicker(
            Key key = null,
            DateTime?initialDate = null,
            DateTime?firstDate   = null,
            DateTime?lastDate    = null,
            ValueChanged <DateTime> onDateChanged           = null,
            ValueChanged <DateTime> onDisplayedMonthChanged = null,
            DatePickerMode initialCalendarMode = DatePickerMode.day,
            material_.SelectableDayPredicate selectableDayPredicate = null
            ) : base(key: key)
        {
            D.assert(initialDate != null);
            D.assert(firstDate != null);
            D.assert(lastDate != null);
            initialDate = utils.dateOnly(initialDate.Value);
            firstDate   = utils.dateOnly(firstDate.Value);
            lastDate    = utils.dateOnly(lastDate.Value);
            D.assert(onDateChanged != null);
            D.assert(initialCalendarMode != null);

            this.onDateChanged           = onDateChanged;
            this.onDisplayedMonthChanged = onDisplayedMonthChanged;
            this.initialCalendarMode     = initialCalendarMode;
            this.selectableDayPredicate  = selectableDayPredicate;
            D.assert(
                !(this.lastDate < this.firstDate),
                () => $"lastDate {lastDate} must be on or after firstDate {firstDate}."
                );
            D.assert(
                !(this.initialDate < this.firstDate),
                () => $"initialDate {initialDate} must be on or after firstDate {firstDate}."
                );
            D.assert(
                !(this.initialDate > this.lastDate),
                () => $"initialDate {initialDate} must be on or before lastDate {lastDate}."
                );
            D.assert(
                selectableDayPredicate == null || selectableDayPredicate(this.initialDate),
                () => $"Provided initialDate {initialDate} must satisfy provided selectableDayPredicate."
                );
        }
        public static Future <DateTime> showDatePicker(
            BuildContext context,
            DateTime initialDate,
            DateTime firstDate,
            DateTime lastDate,
            DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
            material_.SelectableDayPredicate selectableDayPredicate = null,
            string helpText                      = null,
            string cancelText                    = null,
            string confirmText                   = null,
            Locale locale                        = null,
            bool useRootNavigator                = true,
            RouteSettings routeSettings          = null,
            TextDirection?textDirection          = null,
            TransitionBuilder builder            = null,
            DatePickerMode initialDatePickerMode = DatePickerMode.day,
            string errorFormatText               = null,
            string errorInvalidText              = null,
            string fieldHintText                 = null,
            string fieldLabelText                = null
            )
        {
            D.assert(context != null);
            initialDate = utils.dateOnly(initialDate);
            firstDate   = utils.dateOnly(firstDate);
            lastDate    = utils.dateOnly(lastDate);

            D.assert(
                !lastDate.isBefore(firstDate),
                () => $"lastDate {lastDate} must be on or after firstDate {firstDate}."
                );
            D.assert(
                !initialDate.isBefore(firstDate),
                () => $"initialDate {initialDate} must be on or after firstDate {firstDate}."
                );
            D.assert(
                !initialDate.isAfter(lastDate),
                () => $"initialDate {initialDate} must be on or before lastDate {lastDate}."
                );
            D.assert(
                selectableDayPredicate == null || selectableDayPredicate(initialDate),
                () => $"Provided initialDate {initialDate} must satisfy provided selectableDayPredicate."
                );

            D.assert(initialEntryMode != null);
            D.assert(initialDatePickerMode != null);
            D.assert(material_.debugCheckHasMaterialLocalizations(context));

            Widget dialog = new _DatePickerDialog(
                initialDate: initialDate,
                firstDate: firstDate,
                lastDate: lastDate,
                initialEntryMode: initialEntryMode,
                selectableDayPredicate: selectableDayPredicate,
                helpText: helpText,
                cancelText: cancelText,
                confirmText: confirmText,
                initialCalendarMode: initialDatePickerMode,
                errorFormatText: errorFormatText,
                errorInvalidText: errorInvalidText,
                fieldHintText: fieldHintText,
                fieldLabelText: fieldLabelText
                );

            if (textDirection != null)
            {
                dialog = new Directionality(
                    textDirection: textDirection.Value,
                    child: dialog
                    );
            }

            if (locale != null)
            {
                dialog = Localizations.overrides(
                    context: context,
                    locale: locale,
                    child: dialog
                    );
            }

            return(material_.showDialog <DateTime>(
                       context: context,
                       useRootNavigator: useRootNavigator,
                       routeSettings: routeSettings,
                       builder: (BuildContext subContext) => { return builder == null ? dialog : builder(subContext, dialog); }
                       ));
        }