1
1
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart' ;
2
2
import 'package:flutter/material.dart' ;
3
+ import 'package:flutter/services.dart' ;
3
4
import 'package:flutter_form_builder/flutter_form_builder.dart' ;
4
5
import 'package:intl/intl.dart' ;
6
+ import 'dart:ui' as ui;
5
7
6
8
class FormBuilderDateTimePicker extends StatefulWidget {
7
9
final String attribute;
@@ -10,10 +12,86 @@ class FormBuilderDateTimePicker extends StatefulWidget {
10
12
final bool readonly;
11
13
final InputDecoration decoration;
12
14
15
+ /// The date/time picker dialogs to show.
16
+ final InputType inputType;
17
+
18
+ /// Allow manual editing of the date/time. Defaults to true. If false, the
19
+ /// picker(s) will be shown every time the field gains focus.
20
+ final bool editable;
21
+
22
+ /// For representing the date as a string e.g.
23
+ /// `DateFormat("EEEE, MMMM d, yyyy 'at' h:mma")`
24
+ /// (Sunday, June 3, 2018 at 9:24pm)
13
25
final DateFormat format;
26
+
27
+ /// The date the calendar opens to when displayed. Defaults to the current date.
28
+ ///
29
+ /// To preset the widget's value, use [initialValue] instead.
30
+ final DateTime initialDate;
31
+
32
+ /// The earliest choosable date. Defaults to 1900.
14
33
final DateTime firstDate;
34
+
35
+ /// The latest choosable date. Defaults to 2100.
15
36
final DateTime lastDate;
16
- final InputType inputType; //TODO: Create own enum
37
+
38
+ /// The initial time prefilled in the picker dialog when it is shown. Defaults
39
+ /// to noon. Explicitly set this to `null` to use the current time.
40
+ final TimeOfDay initialTime;
41
+
42
+ /// If defined, the TextField [decoration] 's [suffixIcon] will be
43
+ /// overridden to reset the input using the icon defined here.
44
+ /// Set this to `null` to stop that behavior. Defaults to [Icons.close] .
45
+ final IconData resetIcon;
46
+
47
+ /// For validating the [DateTime] . The value passed will be `null` if
48
+ /// [format] fails to parse the text.
49
+ final FormFieldValidator <DateTime > validator;
50
+
51
+ /// Called when an enclosing form is saved. The value passed will be `null`
52
+ /// if [format] fails to parse the text.
53
+ final FormFieldSetter <DateTime > onSaved;
54
+
55
+ /// Corresponds to the [showDatePicker()] parameter. Defaults to
56
+ /// [DatePickerMode.day] .
57
+ final DatePickerMode initialDatePickerMode;
58
+
59
+ /// Corresponds to the [showDatePicker()] parameter.
60
+ ///
61
+ /// See [GlobalMaterialLocalizations] (https://docs.flutter.io/flutter/flutter_localizations/GlobalMaterialLocalizations-class.html)
62
+ /// for acceptable values.
63
+ final Locale locale;
64
+
65
+ /// Corresponds to the [showDatePicker()] parameter.
66
+ final bool Function (DateTime ) selectableDayPredicate;
67
+
68
+ /// Corresponds to the [showDatePicker()] parameter.
69
+ final ui.TextDirection textDirection;
70
+
71
+ /// Called when an enclosing form is submitted. The value passed will be
72
+ /// `null` if [format] fails to parse the text.
73
+ final ValueChanged <DateTime > onFieldSubmitted;
74
+ final TextEditingController controller;
75
+ final FocusNode focusNode;
76
+ final TextInputType keyboardType;
77
+ final TextStyle style;
78
+ final TextAlign textAlign;
79
+
80
+ /// Preset the widget's value.
81
+ final bool autofocus;
82
+ final bool autovalidate;
83
+ final bool obscureText;
84
+ final bool autocorrect;
85
+ final bool maxLengthEnforced;
86
+ final int maxLines;
87
+ final int maxLength;
88
+ final List <TextInputFormatter > inputFormatters;
89
+ final bool enabled;
90
+
91
+ /// Called whenever the state's value changes, e.g. after picker value(s)
92
+ /// have been selected or when the field loses focus. To listen for all text
93
+ /// changes, use the [controller] and [focusNode] .
94
+ final ValueChanged <DateTime > onChanged;
17
95
18
96
FormBuilderDateTimePicker ({
19
97
@required this .attribute,
@@ -25,6 +103,32 @@ class FormBuilderDateTimePicker extends StatefulWidget {
25
103
this .firstDate,
26
104
this .lastDate,
27
105
this .decoration = const InputDecoration (),
106
+ this .editable = true ,
107
+ this .onChanged,
108
+ this .resetIcon = Icons .close,
109
+ this .initialDate,
110
+ this .initialTime = const TimeOfDay (hour: 12 , minute: 0 ),
111
+ this .validator,
112
+ this .onSaved,
113
+ this .onFieldSubmitted,
114
+ this .autovalidate = false ,
115
+ this .initialDatePickerMode,
116
+ this .locale,
117
+ this .selectableDayPredicate,
118
+ this .textDirection,
119
+ this .controller,
120
+ this .focusNode,
121
+ this .keyboardType = TextInputType .text,
122
+ this .style,
123
+ this .textAlign = TextAlign .start,
124
+ this .autofocus = false ,
125
+ this .obscureText = false ,
126
+ this .autocorrect = true ,
127
+ this .maxLengthEnforced = true ,
128
+ this .enabled,
129
+ this .maxLines = 1 ,
130
+ this .maxLength,
131
+ this .inputFormatters,
28
132
});
29
133
30
134
@override
@@ -71,6 +175,29 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
71
175
return widget.validators[i](val);
72
176
}
73
177
},
178
+ onChanged: widget.onChanged,
179
+ onFieldSubmitted: widget.onFieldSubmitted,
180
+ autovalidate: widget.autovalidate,
181
+ style: widget.style,
182
+ textDirection: widget.textDirection,
183
+ textAlign: widget.textAlign,
184
+ maxLength: widget.maxLength,
185
+ autofocus: widget.autofocus,
186
+ autocorrect: widget.autocorrect,
187
+ controller: widget.controller,
188
+ editable: widget.editable,
189
+ focusNode: widget.focusNode,
190
+ initialDate: widget.initialDate,
191
+ initialDatePickerMode: widget.initialDatePickerMode,
192
+ initialTime: widget.initialTime,
193
+ inputFormatters: widget.inputFormatters,
194
+ keyboardType: widget.keyboardType,
195
+ locale: widget.locale,
196
+ maxLengthEnforced: widget.maxLengthEnforced,
197
+ maxLines: widget.maxLines,
198
+ obscureText: widget.obscureText,
199
+ resetIcon: widget.resetIcon,
200
+ selectableDayPredicate: widget.selectableDayPredicate,
74
201
);
75
202
}
76
203
}
0 commit comments