Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/src/fields/form_builder_date_time_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class FormBuilderDateTimePicker extends FormBuilderFieldDecoration<DateTime> {
/// (Sunday, June 3, 2018 at 9:24pm)
final DateFormat? format;

/// The date the calendar opens to when displayed. Defaults to the current date.
/// The date the calendar opens to when displayed. Defaults to null.
///
/// To preset the widget's value, use [initialValue] instead.
final DateTime? initialDate;
Expand Down Expand Up @@ -327,7 +327,7 @@ class _FormBuilderDateTimePickerState extends FormBuilderFieldDecorationState<
context: context,
selectableDayPredicate: widget.selectableDayPredicate,
initialDatePickerMode: widget.initialDatePickerMode,
initialDate: currentValue ?? widget.initialDate ?? DateTime.now(),
initialDate: currentValue ?? widget.initialDate,
firstDate: widget.firstDate ?? DateTime(1900),
lastDate: widget.lastDate ?? DateTime(2100),
locale: widget.locale,
Expand Down
28 changes: 27 additions & 1 deletion test/src/fields/form_builder_date_time_picker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void main() {
expect(formValue<DateTime>(widgetName),
DateTime(dateNow.year, dateNow.month, testDay, 12));
});
testWidgets('input keyboard type', (WidgetTester tester) async {
testWidgets(
'should change to text field and show keyboard when edit icon is pressed',
(WidgetTester tester) async {
const widgetName = 'fdtp3';
final widgetKey = UniqueKey();
const keyboardType = TextInputType.datetime;
Expand All @@ -63,6 +65,30 @@ void main() {
final textField = tester.widget<TextField>(find.byType(TextField).first);
expect(textField.keyboardType, equals(keyboardType));
});
testWidgets('should show a past year when set on lastDate',
(WidgetTester tester) async {
const widgetName = 'fdtp3';
final widgetKey = UniqueKey();
const confirmText = 'OK';
const cancelText = 'CANCEL';
final year = 2006;

final testWidget = FormBuilderDateTimePicker(
key: widgetKey,
name: widgetName,
confirmText: confirmText,
cancelText: cancelText,
initialDate: null,
lastDate: DateTime(year, 12, 31),
);
await tester.pumpWidget(buildTestableFieldWidget(testWidget));
await tester.tap(find.byKey(widgetKey));
await tester.pumpAndSettle();

expect(find.text(confirmText), findsOneWidget);
expect(find.text(cancelText), findsOneWidget);
expect(find.text('December ${year.toString()}'), findsOneWidget);
});
group('initial value -', () {
testWidgets('to FormBuilder', (WidgetTester tester) async {
const widgetName = 'fdtp2';
Expand Down
Loading