Ejemplo n.º 1
0
        public static IPromise <object> showDatePicker(
            BuildContext context,
            DateTime initialDate,
            DateTime firstDate,
            DateTime lastDate,
            SelectableDayPredicate selectableDayPredicate = null,
            DatePickerMode initialDatePickerMode          = DatePickerMode.day,
            Locale locale             = null,
            TransitionBuilder builder = null
            )
        {
            D.assert(initialDate >= firstDate, () => "initialDate must be on or after firstDate");
            D.assert(initialDate <= lastDate, () => "initialDate must be on or before lastDate");
            D.assert(firstDate <= lastDate, () => "lastDate must be on or after firstDate");
            D.assert(
                selectableDayPredicate == null || selectableDayPredicate(initialDate),
                () => "Provided initialDate must satisfy provided selectableDayPredicate"
                );
            D.assert(context != null);
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));

            Widget child = new _DatePickerDialog(
                initialDate: initialDate,
                firstDate: firstDate,
                lastDate: lastDate,
                selectableDayPredicate: selectableDayPredicate,
                initialDatePickerMode: initialDatePickerMode
                );

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

            return(DialogUtils.showDialog(
                       context: context,
                       builder: (BuildContext _context) => { return builder == null ? child : builder(_context, child); }
                       ));
        }
        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); }
                       ));
        }