@@ -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
+ /**************** START 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,49 @@ 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
+ /// 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
+
157
201
/// Preset the widget's value.
158
202
final bool autofocus;
159
203
final bool obscureText;
@@ -188,17 +232,9 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
188
232
final double cursorWidth;
189
233
final TextCapitalization textCapitalization;
190
234
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
235
final DatePickerEntryMode initialEntryMode;
199
236
final RouteSettings ? routeSettings;
200
237
201
- final TimePickerEntryMode timePickerInitialEntryMode;
202
238
final StrutStyle ? strutStyle;
203
239
final bool Function (DateTime day)? selectableDayPredicate;
204
240
final Offset ? anchorPoint;
@@ -226,6 +262,12 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
226
262
this .initialTime = const TimeOfDay (hour: 12 , minute: 0 ),
227
263
this .keyboardType,
228
264
this .textAlign = TextAlign .start,
265
+ this .shouldExpandedField = false ,
266
+ this .decoration,
267
+ this .prefix,
268
+ this .contentPadding,
269
+ this .helper,
270
+ this .errorBuilder,
229
271
this .autofocus = false ,
230
272
this .obscureText = false ,
231
273
this .autocorrect = true ,
@@ -236,7 +278,6 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
236
278
this .textCapitalization = TextCapitalization .none,
237
279
this .useRootNavigator = true ,
238
280
this .initialEntryMode = DatePickerEntryMode .calendar,
239
- this .timePickerInitialEntryMode = TimePickerEntryMode .dial,
240
281
this .format,
241
282
this .initialDate,
242
283
this .firstDate,
@@ -258,13 +299,6 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
258
299
this .cursorRadius = const Radius .circular (2.0 ),
259
300
this .cursorColor,
260
301
this .keyboardAppearance,
261
- this .cancelText,
262
- this .confirmText,
263
- this .errorFormatText,
264
- this .errorInvalidText,
265
- this .fieldHintText,
266
- this .fieldLabelText,
267
- this .helpText,
268
302
this .routeSettings,
269
303
this .strutStyle,
270
304
this .selectableDayPredicate,
@@ -275,7 +309,7 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
275
309
builder: (FormFieldState <DateTime ?> field) {
276
310
final state = field as _FormBuilderCupertinoDateTimePickerState ;
277
311
278
- return FocusTraversalGroup (
312
+ final fieldWidget = FocusTraversalGroup (
279
313
policy: ReadingOrderTraversalPolicy (),
280
314
child: CupertinoTextField (
281
315
onTap: () => state.showPicker (),
@@ -284,7 +318,7 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
284
318
textAlignVertical: textAlignVertical,
285
319
maxLength: maxLength,
286
320
autofocus: autofocus,
287
- // FIXME: decoration: state. decoration,
321
+ decoration: decoration,
288
322
readOnly: true ,
289
323
enabled: state.enabled,
290
324
autocorrect: autocorrect,
@@ -311,6 +345,20 @@ class FormBuilderCupertinoDateTimePicker extends FormBuilderField<DateTime> {
311
345
maxLengthEnforcement: maxLengthEnforcement,
312
346
),
313
347
);
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
+ );
314
362
},
315
363
);
316
364
0 commit comments