@@ -8,6 +8,8 @@ import 'package:intl/intl.dart';
8
8
9
9
import 'package:flutter_form_builder/flutter_form_builder.dart' ;
10
10
11
+ /**************** START Imported from flutter/material.dart ****************/
12
+
11
13
/// Initial display of a calendar date picker.
12
14
///
13
15
/// Either a grid of available years or a monthly calendar.
@@ -91,10 +93,9 @@ enum DatePickerEntryMode {
91
93
/// There is no user interface to switch to another mode.
92
94
inputOnly,
93
95
}
96
+ /**************** END Imported from flutter/material.dart ****************/
94
97
95
- enum InputType { date, time, both }
96
-
97
- /// Field for `Date` , `Time` and `DateTime` input
98
+ /// A [CupertinoDateTimePicker] that integrates with [FormBuilder] .
98
99
class FormBuilderCupertinoDateTimePicker extends FormBuilderField <DateTime > {
99
100
/// The date/time picker dialogs to show.
100
101
final InputType inputType;
@@ -154,6 +155,43 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
154
155
final TextAlign textAlign;
155
156
final TextAlignVertical ? textAlignVertical;
156
157
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
+ /// A widget that is displayed at the start of the row.
165
+ ///
166
+ /// The [prefix] parameter is displayed at the start of the row. Standard iOS
167
+ /// guidelines encourage passing a [Text] widget to [prefix] to detail the
168
+ /// nature of the row's [child] widget. If null, the [child] widget will take
169
+ /// up all horizontal space in the row.
170
+ final Widget ? prefix;
171
+
172
+ /// Content padding for the row.
173
+ ///
174
+ /// Defaults to the standard iOS padding for form rows. If no edge insets are
175
+ /// intended, explicitly pass [EdgeInsets.zero] to [contentPadding] .
176
+ final EdgeInsetsGeometry ? contentPadding;
177
+
178
+ /// A widget that is displayed underneath the [prefix] and [child] widgets.
179
+ ///
180
+ /// The [helper] appears in primary label coloring, and is meant to inform the
181
+ /// user about interaction with the child widget. The row becomes taller in
182
+ /// order to display the [helper] widget underneath [prefix] and [child] . If
183
+ /// null, the row is shorter.
184
+ final Widget ? helper;
185
+
186
+ /// A builder widget that is displayed underneath the [prefix] and [child] widgets.
187
+ ///
188
+ /// The [error] widget is primarily used to inform users of input errors. When
189
+ /// a [Text] is given to [error] , it will be shown in
190
+ /// [CupertinoColors.destructiveRed] coloring and medium-weighted font. The
191
+ /// row becomes taller in order to display the [helper] widget underneath
192
+ /// [prefix] and [child] . If null, the row is shorter.
193
+ final Widget ? Function (String error)? errorBuilder;
194
+
157
195
/// Preset the widget's value.
158
196
final bool autofocus;
159
197
final bool obscureText;
@@ -188,17 +226,9 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
188
226
final double cursorWidth;
189
227
final TextCapitalization textCapitalization;
190
228
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;
198
229
final DatePickerEntryMode initialEntryMode;
199
230
final RouteSettings ? routeSettings;
200
231
201
- final TimePickerEntryMode timePickerInitialEntryMode;
202
232
final StrutStyle ? strutStyle;
203
233
final bool Function (DateTime day)? selectableDayPredicate;
204
234
final Offset ? anchorPoint;
@@ -226,6 +256,11 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
226
256
this .initialTime = const TimeOfDay (hour: 12 , minute: 0 ),
227
257
this .keyboardType,
228
258
this .textAlign = TextAlign .start,
259
+ this .shouldExpandedField = false ,
260
+ this .prefix,
261
+ this .contentPadding,
262
+ this .helper,
263
+ this .errorBuilder,
229
264
this .autofocus = false ,
230
265
this .obscureText = false ,
231
266
this .autocorrect = true ,
@@ -236,7 +271,6 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
236
271
this .textCapitalization = TextCapitalization .none,
237
272
this .useRootNavigator = true ,
238
273
this .initialEntryMode = DatePickerEntryMode .calendar,
239
- this .timePickerInitialEntryMode = TimePickerEntryMode .dial,
240
274
this .format,
241
275
this .initialDate,
242
276
this .firstDate,
@@ -258,13 +292,6 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
258
292
this .cursorRadius = const Radius .circular (2.0 ),
259
293
this .cursorColor,
260
294
this .keyboardAppearance,
261
- this .cancelText,
262
- this .confirmText,
263
- this .errorFormatText,
264
- this .errorInvalidText,
265
- this .fieldHintText,
266
- this .fieldLabelText,
267
- this .helpText,
268
295
this .routeSettings,
269
296
this .strutStyle,
270
297
this .selectableDayPredicate,
@@ -275,7 +302,7 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
275
302
builder: (FormFieldState <DateTime ?> field) {
276
303
final state = field as _FormBuilderCupertinoDateTimePickerState ;
277
304
278
- return FocusTraversalGroup (
305
+ final fieldWidget = FocusTraversalGroup (
279
306
policy: ReadingOrderTraversalPolicy (),
280
307
child: CupertinoTextField (
281
308
onTap: () => state.showPicker (),
@@ -284,7 +311,6 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
284
311
textAlignVertical: textAlignVertical,
285
312
maxLength: maxLength,
286
313
autofocus: autofocus,
287
- // FIXME: decoration: state.decoration,
288
314
readOnly: true ,
289
315
enabled: state.enabled,
290
316
autocorrect: autocorrect,
@@ -311,6 +337,20 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
311
337
maxLengthEnforcement: maxLengthEnforcement,
312
338
),
313
339
);
340
+
341
+ return CupertinoFormRow (
342
+ error: state.hasError
343
+ ? errorBuilder != null
344
+ ? errorBuilder (state.errorText ?? '' )
345
+ : Text (state.errorText ?? '' )
346
+ : null ,
347
+ helper: helper,
348
+ padding: contentPadding,
349
+ prefix: prefix,
350
+ child: shouldExpandedField
351
+ ? SizedBox (width: double .infinity, child: fieldWidget)
352
+ : fieldWidget,
353
+ );
314
354
},
315
355
);
316
356
0 commit comments