@@ -8,6 +8,8 @@ import 'package:intl/intl.dart';
88
99import 'package:flutter_form_builder/flutter_form_builder.dart' ;
1010
11+ /**************** START Imported from flutter/material.dart ****************/
12+
1113/// Initial display of a calendar date picker.
1214///
1315/// Either a grid of available years or a monthly calendar.
@@ -91,10 +93,9 @@ enum DatePickerEntryMode {
9193 /// There is no user interface to switch to another mode.
9294 inputOnly,
9395}
96+ /**************** START Imported from flutter/material.dart ****************/
9497
95- enum InputType { date, time, both }
96-
97- /// Field for `Date` , `Time` and `DateTime` input
98+ /// A [CupertinoDateTimePicker] that integrates with [FormBuilder] .
9899class FormBuilderCupertinoDateTimePicker extends FormBuilderField <DateTime > {
99100 /// The date/time picker dialogs to show.
100101 final InputType inputType;
@@ -154,6 +155,49 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
154155 final TextAlign textAlign;
155156 final TextAlignVertical ? textAlignVertical;
156157
158+ /// Defines whether the field input expands to fill the entire width
159+ /// of the row field.
160+ ///
161+ /// By default `false`
162+ final bool shouldExpandedField;
163+
164+ /// Controls the [BoxDecoration] of the box behind the text input.
165+ ///
166+ /// Defaults to having a rounded rectangle grey border and can be null to have
167+ /// no box decoration.
168+ final BoxDecoration ? decoration;
169+
170+ /// A widget that is displayed at the start of the row.
171+ ///
172+ /// The [prefix] parameter is displayed at the start of the row. Standard iOS
173+ /// guidelines encourage passing a [Text] widget to [prefix] to detail the
174+ /// nature of the row's [child] widget. If null, the [child] widget will take
175+ /// up all horizontal space in the row.
176+ final Widget ? prefix;
177+
178+ /// Content padding for the row.
179+ ///
180+ /// Defaults to the standard iOS padding for form rows. If no edge insets are
181+ /// intended, explicitly pass [EdgeInsets.zero] to [contentPadding] .
182+ final EdgeInsetsGeometry ? contentPadding;
183+
184+ /// A widget that is displayed underneath the [prefix] and [child] widgets.
185+ ///
186+ /// The [helper] appears in primary label coloring, and is meant to inform the
187+ /// user about interaction with the child widget. The row becomes taller in
188+ /// order to display the [helper] widget underneath [prefix] and [child] . If
189+ /// null, the row is shorter.
190+ final Widget ? helper;
191+
192+ /// A builder widget that is displayed underneath the [prefix] and [child] widgets.
193+ ///
194+ /// The [error] widget is primarily used to inform users of input errors. When
195+ /// a [Text] is given to [error] , it will be shown in
196+ /// [CupertinoColors.destructiveRed] coloring and medium-weighted font. The
197+ /// row becomes taller in order to display the [helper] widget underneath
198+ /// [prefix] and [child] . If null, the row is shorter.
199+ final Widget ? Function (String error)? errorBuilder;
200+
157201 /// Preset the widget's value.
158202 final bool autofocus;
159203 final bool obscureText;
@@ -188,17 +232,9 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
188232 final double cursorWidth;
189233 final TextCapitalization textCapitalization;
190234
191- final String ? cancelText;
192- final String ? confirmText;
193- final String ? errorFormatText;
194- final String ? errorInvalidText;
195- final String ? fieldHintText;
196- final String ? fieldLabelText;
197- final String ? helpText;
198235 final DatePickerEntryMode initialEntryMode;
199236 final RouteSettings ? routeSettings;
200237
201- final TimePickerEntryMode timePickerInitialEntryMode;
202238 final StrutStyle ? strutStyle;
203239 final bool Function (DateTime day)? selectableDayPredicate;
204240 final Offset ? anchorPoint;
@@ -226,6 +262,12 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
226262 this .initialTime = const TimeOfDay (hour: 12 , minute: 0 ),
227263 this .keyboardType,
228264 this .textAlign = TextAlign .start,
265+ this .shouldExpandedField = false ,
266+ this .decoration,
267+ this .prefix,
268+ this .contentPadding,
269+ this .helper,
270+ this .errorBuilder,
229271 this .autofocus = false ,
230272 this .obscureText = false ,
231273 this .autocorrect = true ,
@@ -236,7 +278,6 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
236278 this .textCapitalization = TextCapitalization .none,
237279 this .useRootNavigator = true ,
238280 this .initialEntryMode = DatePickerEntryMode .calendar,
239- this .timePickerInitialEntryMode = TimePickerEntryMode .dial,
240281 this .format,
241282 this .initialDate,
242283 this .firstDate,
@@ -258,13 +299,6 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
258299 this .cursorRadius = const Radius .circular (2.0 ),
259300 this .cursorColor,
260301 this .keyboardAppearance,
261- this .cancelText,
262- this .confirmText,
263- this .errorFormatText,
264- this .errorInvalidText,
265- this .fieldHintText,
266- this .fieldLabelText,
267- this .helpText,
268302 this .routeSettings,
269303 this .strutStyle,
270304 this .selectableDayPredicate,
@@ -275,7 +309,7 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
275309 builder: (FormFieldState <DateTime ?> field) {
276310 final state = field as _FormBuilderCupertinoDateTimePickerState ;
277311
278- return FocusTraversalGroup (
312+ final fieldWidget = FocusTraversalGroup (
279313 policy: ReadingOrderTraversalPolicy (),
280314 child: CupertinoTextField (
281315 onTap: () => state.showPicker (),
@@ -284,7 +318,7 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
284318 textAlignVertical: textAlignVertical,
285319 maxLength: maxLength,
286320 autofocus: autofocus,
287- // FIXME: decoration: state. decoration,
321+ decoration: decoration,
288322 readOnly: true ,
289323 enabled: state.enabled,
290324 autocorrect: autocorrect,
@@ -311,6 +345,20 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
311345 maxLengthEnforcement: maxLengthEnforcement,
312346 ),
313347 );
348+
349+ return CupertinoFormRow (
350+ error: state.hasError
351+ ? errorBuilder != null
352+ ? errorBuilder (state.errorText ?? '' )
353+ : Text (state.errorText ?? '' )
354+ : null ,
355+ helper: helper,
356+ padding: contentPadding,
357+ prefix: prefix,
358+ child: shouldExpandedField
359+ ? SizedBox (width: double .infinity, child: fieldWidget)
360+ : fieldWidget,
361+ );
314362 },
315363 );
316364
0 commit comments