mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix last month not being displayed if last date is selected in DateRangePicker (#66542)
This commit is contained in:
parent
0bca44cf8d
commit
693c4a7ccc
@ -109,8 +109,8 @@ class _CalendarDateRangePickerState extends State<CalendarDateRangePicker> {
|
||||
// Calculate the index for the initially displayed month. This is needed to
|
||||
// divide the list of months into two `SliverList`s.
|
||||
final DateTime initialDate = widget.initialStartDate ?? widget.currentDate;
|
||||
if (widget.firstDate.isBefore(initialDate) &&
|
||||
widget.lastDate.isAfter(initialDate)) {
|
||||
if (!initialDate.isBefore(widget.firstDate) &&
|
||||
!initialDate.isAfter(widget.lastDate)) {
|
||||
_initialMonthIndex = utils.monthDelta(widget.firstDate, initialDate);
|
||||
}
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ import 'feedback_tester.dart';
|
||||
void main() {
|
||||
DateTime firstDate;
|
||||
DateTime lastDate;
|
||||
DateTime currentDate;
|
||||
DateTimeRange initialDateRange;
|
||||
DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar;
|
||||
|
||||
@ -31,6 +32,7 @@ void main() {
|
||||
setUp(() {
|
||||
firstDate = DateTime(2015, DateTime.january, 1);
|
||||
lastDate = DateTime(2016, DateTime.december, 31);
|
||||
currentDate = null;
|
||||
initialDateRange = DateTimeRange(
|
||||
start: DateTime(2016, DateTime.january, 15),
|
||||
end: DateTime(2016, DateTime.january, 25),
|
||||
@ -79,6 +81,7 @@ void main() {
|
||||
initialDateRange: initialDateRange,
|
||||
firstDate: firstDate,
|
||||
lastDate: lastDate,
|
||||
currentDate: currentDate,
|
||||
initialEntryMode: initialEntryMode,
|
||||
cancelText: cancelText,
|
||||
confirmText: confirmText,
|
||||
@ -122,6 +125,52 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('Last month header should be visible if last date is selected',
|
||||
(WidgetTester tester) async {
|
||||
firstDate = DateTime(2015, DateTime.january, 1);
|
||||
lastDate = DateTime(2016, DateTime.december, 31);
|
||||
initialDateRange = DateTimeRange(
|
||||
start: lastDate,
|
||||
end: lastDate,
|
||||
);
|
||||
await preparePicker(tester, (Future<DateTimeRange> range) async {
|
||||
// December header should be showing, but no November
|
||||
expect(find.text('December 2016'), findsOneWidget);
|
||||
expect(find.text('November 2016'), findsNothing);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('First month header should be visible if first date is selected',
|
||||
(WidgetTester tester) async {
|
||||
firstDate = DateTime(2015, DateTime.january, 1);
|
||||
lastDate = DateTime(2016, DateTime.december, 31);
|
||||
initialDateRange = DateTimeRange(
|
||||
start: firstDate,
|
||||
end: firstDate,
|
||||
);
|
||||
await preparePicker(tester, (Future<DateTimeRange> range) async {
|
||||
// January and February headers should be showing, but no March
|
||||
expect(find.text('January 2015'), findsOneWidget);
|
||||
expect(find.text('February 2015'), findsOneWidget);
|
||||
expect(find.text('March 2015'), findsNothing);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('Current month header should be visible if no date is selected',
|
||||
(WidgetTester tester) async {
|
||||
firstDate = DateTime(2015, DateTime.january, 1);
|
||||
lastDate = DateTime(2016, DateTime.december, 31);
|
||||
currentDate = DateTime(2016, DateTime.september, 1);
|
||||
initialDateRange = null;
|
||||
|
||||
await preparePicker(tester, (Future<DateTimeRange> range) async {
|
||||
// September and October headers should be showing, but no August
|
||||
expect(find.text('September 2016'), findsOneWidget);
|
||||
expect(find.text('October 2016'), findsOneWidget);
|
||||
expect(find.text('August 2016'), findsNothing);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('Can cancel', (WidgetTester tester) async {
|
||||
await preparePicker(tester, (Future<DateTimeRange> range) async {
|
||||
await tester.tap(find.byIcon(Icons.close));
|
||||
@ -372,10 +421,10 @@ void main() {
|
||||
|
||||
testWidgets('Navigating with arrow keys scrolls as needed', (WidgetTester tester) async {
|
||||
await preparePicker(tester, (Future<DateTimeRange> range) async {
|
||||
// Jan and Feb headers should be showing, but no Mar
|
||||
// Jan and Feb headers should be showing, but no March
|
||||
expect(find.text('January 2016'), findsOneWidget);
|
||||
expect(find.text('February 2016'), findsOneWidget);
|
||||
expect(find.text('Mar 2016'), findsNothing);
|
||||
expect(find.text('March 2016'), findsNothing);
|
||||
|
||||
// Navigate to the grid
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user