Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
693c4a7c
Unverified
Commit
693c4a7c
authored
Sep 26, 2020
by
Nguyễn Thanh Hải
Committed by
GitHub
Sep 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix last month not being displayed if last date is selected in DateRangePicker (#66542)
parent
0bca44cf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
4 deletions
+53
-4
calendar_date_range_picker.dart
.../lib/src/material/pickers/calendar_date_range_picker.dart
+2
-2
date_range_picker_test.dart
packages/flutter/test/material/date_range_picker_test.dart
+51
-2
No files found.
packages/flutter/lib/src/material/pickers/calendar_date_range_picker.dart
View file @
693c4a7c
...
...
@@ -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
(
initial
Date
)
&&
widget
.
lastDate
.
isAfter
(
initial
Date
))
{
if
(
!
initialDate
.
isBefore
(
widget
.
first
Date
)
&&
!
initialDate
.
isAfter
(
widget
.
last
Date
))
{
_initialMonthIndex
=
utils
.
monthDelta
(
widget
.
firstDate
,
initialDate
);
}
...
...
packages/flutter/test/material/date_range_picker_test.dart
View file @
693c4a7c
...
...
@@ -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 Mar
ch
expect
(
find
.
text
(
'January 2016'
),
findsOneWidget
);
expect
(
find
.
text
(
'February 2016'
),
findsOneWidget
);
expect
(
find
.
text
(
'Mar 2016'
),
findsNothing
);
expect
(
find
.
text
(
'Mar
ch
2016'
),
findsNothing
);
// Navigate to the grid
await
tester
.
sendKeyEvent
(
LogicalKeyboardKey
.
tab
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment