Unverified Commit 539510b4 authored by Darren Austin's avatar Darren Austin Committed by GitHub

Added the ability to bring up the date picker dialogs in calendar or text...

Added the ability to bring up the date picker dialogs in calendar or text input only modes that don't allow the user to switch. (#76343)
parent a46139a2
...@@ -144,22 +144,38 @@ class DateUtils { ...@@ -144,22 +144,38 @@ class DateUtils {
} }
} }
/// Mode of the date picker dialog. /// Mode of date entry method for the date picker dialog.
/// ///
/// Either a calendar or text input. In [calendar] mode, a calendar view is /// In [calendar] mode, a calendar grid is displayed and the user taps the
/// displayed and the user taps the day they wish to select. In [input] mode a /// day they wish to select. In [input] mode a TextField] is displayed and
/// [TextField] is displayed and the user types in the date they wish to select. /// the user types in the date they wish to select.
///
/// [calendarOnly] and [inputOnly] are variants of the above that don't
/// allow the user to change to the mode.
/// ///
/// See also: /// See also:
/// ///
/// * [showDatePicker] and [showDateRangePicker], which use this to control /// * [showDatePicker] and [showDateRangePicker], which use this to control
/// the initial entry mode of their dialogs. /// the initial entry mode of their dialogs.
enum DatePickerEntryMode { enum DatePickerEntryMode {
/// Tapping on a calendar. /// User picks a date from calendar grid. Can switch to [input] by activating
/// a mode button in the dialog.
calendar, calendar,
/// Text input. /// User can input the date by typing it into a text field.
///
/// Can switch to [calendar] by activating a mode button in the dialog.
input, input,
/// User can only pick a date from calendar grid.
///
/// There is no user interface to switch to another mode.
calendarOnly,
/// User can only input the date by typing it into a text field.
///
/// There is no user interface to switch to another mode.
inputOnly,
} }
/// Initial display of a calendar date picker. /// Initial display of a calendar date picker.
......
...@@ -132,7 +132,7 @@ void main() { ...@@ -132,7 +132,7 @@ void main() {
}); });
}); });
testWidgets('Can toggle to input entry mode', (WidgetTester tester) async { testWidgets('Can switch from calendar to input entry mode', (WidgetTester tester) async {
await prepareDatePicker(tester, (Future<DateTime?> date) async { await prepareDatePicker(tester, (Future<DateTime?> date) async {
expect(find.byType(TextField), findsNothing); expect(find.byType(TextField), findsNothing);
await tester.tap(find.byIcon(Icons.edit)); await tester.tap(find.byIcon(Icons.edit));
...@@ -141,7 +141,33 @@ void main() { ...@@ -141,7 +141,33 @@ void main() {
}); });
}); });
testWidgets('Toggle to input mode keeps selected date', (WidgetTester tester) async { testWidgets('Can switch from input to calendar entry mode', (WidgetTester tester) async {
initialEntryMode = DatePickerEntryMode.input;
await prepareDatePicker(tester, (Future<DateTime?> date) async {
expect(find.byType(TextField), findsOneWidget);
await tester.tap(find.byIcon(Icons.calendar_today));
await tester.pumpAndSettle();
expect(find.byType(TextField), findsNothing);
});
});
testWidgets('Can not switch out of calendarOnly mode', (WidgetTester tester) async {
initialEntryMode = DatePickerEntryMode.calendarOnly;
await prepareDatePicker(tester, (Future<DateTime?> date) async {
expect(find.byType(TextField), findsNothing);
expect(find.byIcon(Icons.edit), findsNothing);
});
});
testWidgets('Can not switch out of inputOnly mode', (WidgetTester tester) async {
initialEntryMode = DatePickerEntryMode.inputOnly;
await prepareDatePicker(tester, (Future<DateTime?> date) async {
expect(find.byType(TextField), findsOneWidget);
expect(find.byIcon(Icons.calendar_today), findsNothing);
});
});
testWidgets('Switching to input mode keeps selected date', (WidgetTester tester) async {
await prepareDatePicker(tester, (Future<DateTime?> date) async { await prepareDatePicker(tester, (Future<DateTime?> date) async {
await tester.tap(find.text('12')); await tester.tap(find.text('12'));
await tester.tap(find.byIcon(Icons.edit)); await tester.tap(find.byIcon(Icons.edit));
......
...@@ -231,7 +231,7 @@ void main() { ...@@ -231,7 +231,7 @@ void main() {
}); });
}); });
testWidgets('Can toggle to input entry mode', (WidgetTester tester) async { testWidgets('Can switch from calendar to input entry mode', (WidgetTester tester) async {
await preparePicker(tester, (Future<DateTimeRange?> range) async { await preparePicker(tester, (Future<DateTimeRange?> range) async {
expect(find.byType(TextField), findsNothing); expect(find.byType(TextField), findsNothing);
await tester.tap(find.byIcon(Icons.edit)); await tester.tap(find.byIcon(Icons.edit));
...@@ -240,7 +240,33 @@ void main() { ...@@ -240,7 +240,33 @@ void main() {
}); });
}); });
testWidgets('Toggle to input mode keeps selected date', (WidgetTester tester) async { testWidgets('Can switch from input to calendar entry mode', (WidgetTester tester) async {
initialEntryMode = DatePickerEntryMode.input;
await preparePicker(tester, (Future<DateTimeRange?> range) async {
expect(find.byType(TextField), findsNWidgets(2));
await tester.tap(find.byIcon(Icons.calendar_today));
await tester.pumpAndSettle();
expect(find.byType(TextField), findsNothing);
});
});
testWidgets('Can not switch out of calendarOnly mode', (WidgetTester tester) async {
initialEntryMode = DatePickerEntryMode.calendarOnly;
await preparePicker(tester, (Future<DateTimeRange?> range) async {
expect(find.byType(TextField), findsNothing);
expect(find.byIcon(Icons.edit), findsNothing);
});
});
testWidgets('Can not switch out of inputOnly mode', (WidgetTester tester) async {
initialEntryMode = DatePickerEntryMode.inputOnly;
await preparePicker(tester, (Future<DateTimeRange?> range) async {
expect(find.byType(TextField), findsNWidgets(2));
expect(find.byIcon(Icons.calendar_today), findsNothing);
});
});
testWidgets('Switching to input mode keeps selected date', (WidgetTester tester) async {
await preparePicker(tester, (Future<DateTimeRange?> range) async { await preparePicker(tester, (Future<DateTimeRange?> range) async {
await tester.tap(find.text('12').first); await tester.tap(find.text('12').first);
await tester.tap(find.text('14').first); await tester.tap(find.text('14').first);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment