Skip to content

Commit 2f2b848

Browse files
committed
Added more options for datepicker from datetime_picker_formfield
1 parent 968881a commit 2f2b848

File tree

1 file changed

+128
-1
lines changed

1 file changed

+128
-1
lines changed

lib/src/inputs/form_builder_date_time_picker.dart

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
22
import 'package:flutter/material.dart';
3+
import 'package:flutter/services.dart';
34
import 'package:flutter_form_builder/flutter_form_builder.dart';
45
import 'package:intl/intl.dart';
6+
import 'dart:ui' as ui;
57

68
class FormBuilderDateTimePicker extends StatefulWidget {
79
final String attribute;
@@ -10,10 +12,86 @@ class FormBuilderDateTimePicker extends StatefulWidget {
1012
final bool readonly;
1113
final InputDecoration decoration;
1214

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)
1325
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.
1433
final DateTime firstDate;
34+
35+
/// The latest choosable date. Defaults to 2100.
1536
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;
1795

1896
FormBuilderDateTimePicker({
1997
@required this.attribute,
@@ -25,6 +103,32 @@ class FormBuilderDateTimePicker extends StatefulWidget {
25103
this.firstDate,
26104
this.lastDate,
27105
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,
28132
});
29133

30134
@override
@@ -71,6 +175,29 @@ class _FormBuilderDateTimePickerState extends State<FormBuilderDateTimePicker> {
71175
return widget.validators[i](val);
72176
}
73177
},
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,
74201
);
75202
}
76203
}

0 commit comments

Comments
 (0)