Skip to content

Commit 3c93a2c

Browse files
committed
Updated package description, added API docs.
1 parent 240067f commit 3c93a2c

File tree

4 files changed

+114
-5
lines changed

4 files changed

+114
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
## 0.0.1
22

3-
* Initial release. Includes functionality to add a DateRange widget into a form.
3+
* Initial release. Includes functionality to add a DateRange widget into a form.
4+
5+
## 0.0.2
6+
7+
* Added dartdoc documentation, updated description.

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class _MyFormFieldState extends State<MyFormField> {
5555
),
5656
validator: (value) {
5757
if (value.start.isBefore(DateTime.now())) {
58-
return 'Please enter a valid date';
58+
return 'Please enter a later start date';
5959
}
6060
return null;
6161
},

lib/date_range_form_field.dart

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,126 @@ class DateRangeField extends FormField<DateTimeRange> {
66
DateRangeField(
77
{Key key,
88
@required BuildContext context,
9+
10+
/// This is the earliest date a user can select.
11+
///
12+
/// If null, this will default to DateTime.now().
913
DateTime firstDate,
14+
15+
/// This is the latest date a user can select.
16+
///
17+
/// If null, this will default to 5 years from now.
1018
DateTime lastDate,
19+
20+
/// currentDate represents the the current day (today).
21+
///
22+
/// If null, this default to DateTime.now().
1123
DateTime currentDate,
24+
25+
/// This argument determines which mode the showDateRangePicker will initially display in.
26+
///
27+
/// It defaults to a scrollable calendar month grid ([DatePickerEntryMode.calendar]).
28+
/// It can also be set to display two text input fields ([DatePickerEntryMode.input]).
1229
DatePickerEntryMode initialEntryMode,
30+
31+
/// This is the label displayed at the top of the [showDateRangePicker] dialog.
32+
///
33+
/// If null, this defaults to 'Select Date Range'.
1334
String helpText,
35+
36+
/// This is the label on the cancel button for the text input mode.
37+
///
38+
/// If null, this defaults to 'CANCEL'.
1439
String cancelText,
40+
41+
/// This is the label on the ok button for the text input mode.
42+
///
43+
/// If null, this defaults to 'OK'.
1544
String confirmText,
45+
46+
/// This is the label on the save button for the calendar view.
47+
///
48+
/// If null, this defaults to 'SAVE'.
1649
String saveText,
50+
51+
/// This is the error message displayed when the input text is not a proper date format.
52+
///
53+
/// For example, if the date format was 'MM-dd-yyyy', and the user enters 'Monday' this message will be displayed.
54+
/// If null, this defaults to 'Invalid format.'.
1755
String errorFormatText,
56+
57+
/// This is the error message displayed when an input is not a selectable date.
58+
///
59+
/// For example, if firstDate was set to 09-01-2020, and the user enters '09-01-2019' this message will be displayed.
60+
/// If null, this defaults to 'Out of range.'.
1861
String errorInvalidText,
62+
63+
/// This is the error message displayed when an input is not a valid date range.
64+
///
65+
/// For example, if the user selects a startDate after the endDate this message will be displayed.
66+
/// If null, this defaults to 'Invalid range.'.
1967
String errorInvalidRangeText,
68+
69+
/// This is the label for the start date input text field.
70+
///
71+
/// If null, this defaults to 'Start Date'.
2072
String fieldStartLabelText,
73+
74+
/// This is the label for the end date input text field.
75+
///
76+
/// If null, this default to 'End Date'.
2177
String fieldEndLabelText,
78+
79+
/// This is the width of the widget.
80+
///
81+
/// If null, this defaults to the width of the screen.
2282
double width,
83+
84+
/// This is the margins of the widget.
85+
///
86+
/// If null, this defaults to EdgeInsets.all(15.0).
2387
EdgeInsets margin,
24-
FocusNode focusNode,
88+
89+
/// This is where you tell the widget what to do when the form is saved.
90+
///
91+
/// For example:
92+
/// ```dart
93+
/// onSaved: (value) {
94+
/// setState(() {
95+
/// myDateRange = value;
96+
/// });
97+
/// }
98+
/// ```
2599
FormFieldSetter<DateTimeRange> onSaved,
100+
101+
/// This is where you can validate the user input.
102+
///
103+
/// For example:
104+
/// ```dart
105+
/// validator: (value) {
106+
/// if (value.start.isBefore(DateTime.now()) {
107+
/// return 'Please enter a later start date.';
108+
/// }
109+
/// return null;
110+
/// }
111+
/// ```
26112
FormFieldValidator<DateTimeRange> validator,
113+
114+
/// This required field is the initial DateTimeRange value of the widget.
115+
///
116+
/// This value will be displayed upon first opening the dialog, and if the user does not choose another value it will be saved when the onSaved method is called.
27117
@required DateTimeRange initialValue,
28118
bool autoValidate = false,
119+
120+
/// This is the format the widget will use for dates.
121+
///
122+
/// Any valid format from the intl package is usable.
123+
/// If null, this will default to 'MM-dd-yyyy'.
29124
DateFormat dateFormat,
125+
126+
/// This is how to decorate and customize the appearance of the widget.
127+
///
128+
/// If null, this will use the defaults from the theme.
30129
InputDecoration decoration = const InputDecoration()})
31130
: assert(context != null),
32131
assert(autoValidate != null),
@@ -40,6 +139,8 @@ class DateRangeField extends FormField<DateTimeRange> {
40139
final InputDecoration inputDecoration = (decoration ??
41140
const InputDecoration())
42141
.applyDefaults(Theme.of(state.context).inputDecorationTheme);
142+
143+
/// This is the dialog to select the date range.
43144
Future<Null> selectDateRange(BuildContext context) async {
44145
DateTimeRange picked = await showDateRangePicker(
45146
context: context,
@@ -49,10 +150,11 @@ class DateRangeField extends FormField<DateTimeRange> {
49150
helpText: helpText ?? 'Select Date Range',
50151
cancelText: cancelText ?? 'CANCEL',
51152
confirmText: confirmText ?? 'OK',
153+
saveText: saveText ?? 'SAVE',
52154
errorFormatText: errorFormatText ?? 'Invalid format.',
53155
errorInvalidText: errorInvalidText ?? 'Out of range.',
54156
errorInvalidRangeText:
55-
errorInvalidRangeText ?? 'Invalid range.',
157+
errorInvalidRangeText ?? 'Invalid range.',
56158
fieldStartHintText: fieldStartLabelText ?? 'Start Date',
57159
fieldEndLabelText: fieldEndLabelText ?? 'End Date');
58160
if (picked != null) {
@@ -61,6 +163,7 @@ class DateRangeField extends FormField<DateTimeRange> {
61163
}
62164

63165
return InkWell(
166+
/// This calls the dialog to select the date range.
64167
onTap: () {
65168
selectDateRange(context);
66169
},
@@ -71,6 +174,8 @@ class DateRangeField extends FormField<DateTimeRange> {
71174
decoration:
72175
inputDecoration.copyWith(errorText: state.errorText),
73176
child: Text(
177+
178+
/// This displays the selected date range when the dialog is closed.
74179
'${format.format(state.value.start)} - ${format.format(state.value.end)}'),
75180
)),
76181
);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: date_range_form_field
2-
description: A Flutter package to create a DateRange FormField widget. The widget enables users to enter a date range that is saved into a DateTimeRange object, and supports InputDecoration and DateFormat properties.
2+
description: A Flutter package to create a widget which allows the user to input a DateRange into a FormField.
33
version: 0.0.1
44
homepage: https://github.com/JMAConsulting/date_range_form_field
55

0 commit comments

Comments
 (0)