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
a9fc9e56
Unverified
Commit
a9fc9e56
authored
Nov 05, 2019
by
LongCatIsLooong
Committed by
GitHub
Nov 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply minimumDate & maximumDate constraints in CupertinoDatePicker date mode (#44149)
parent
7dceec21
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
328 additions
and
117 deletions
+328
-117
date_picker.dart
packages/flutter/lib/src/cupertino/date_picker.dart
+236
-115
date_picker_test.dart
packages/flutter/test/cupertino/date_picker_test.dart
+92
-2
No files found.
packages/flutter/lib/src/cupertino/date_picker.dart
View file @
a9fc9e56
This diff is collapsed.
Click to expand it.
packages/flutter/test/cupertino/date_picker_test.dart
View file @
a9fc9e56
...
...
@@ -216,8 +216,9 @@ void main() {
);
// Distance between the first column and the last column.
final
double
distance
=
tester
.
getCenter
(
find
.
text
(
'sec.'
)).
dx
-
tester
.
getCenter
(
find
.
text
(
'12'
)).
dx
;
final
double
distance
=
tester
.
getCenter
(
find
.
text
(
'sec.'
)).
dx
-
tester
.
getCenter
(
find
.
text
(
'12'
),
).
dx
;
await
tester
.
pumpWidget
(
CupertinoApp
(
...
...
@@ -371,6 +372,28 @@ void main() {
expect
(
newDateTime
.
minute
,
6
);
});
test
(
'initial date honors minimumDate & maximumDate'
,
()
{
expect
(()
{
CupertinoDatePicker
(
onDateTimeChanged:
(
DateTime
d
)
{
},
initialDateTime:
DateTime
(
2018
,
10
,
10
),
minimumDate:
DateTime
(
2018
,
10
,
11
),
);
},
throwsAssertionError
,
);
expect
(()
{
CupertinoDatePicker
(
onDateTimeChanged:
(
DateTime
d
)
{
},
initialDateTime:
DateTime
(
2018
,
10
,
10
),
maximumDate:
DateTime
(
2018
,
10
,
9
),
);
},
throwsAssertionError
,
);
});
testWidgets
(
'changing initialDateTime after first build does not do anything'
,
(
WidgetTester
tester
)
async
{
DateTime
selectedDateTime
;
await
tester
.
pumpWidget
(
...
...
@@ -635,6 +658,73 @@ void main() {
);
});
testWidgets
(
'picker automatically scrolls away from invalid date, '
"and onDateTimeChanged doesn't report these dates"
,
(
WidgetTester
tester
)
async
{
DateTime
date
;
// 2016 is a leap year.
final
DateTime
minimum
=
DateTime
(
2016
,
2
,
29
);
final
DateTime
maximum
=
DateTime
(
2018
,
12
,
31
);
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
Center
(
child:
SizedBox
(
height:
400.0
,
width:
400.0
,
child:
CupertinoDatePicker
(
mode:
CupertinoDatePickerMode
.
date
,
minimumDate:
minimum
,
maximumDate:
maximum
,
onDateTimeChanged:
(
DateTime
newDate
)
{
date
=
newDate
;
// Callback doesn't transiently go into invalid dates.
expect
(
newDate
.
isAtSameMomentAs
(
minimum
)
||
newDate
.
isAfter
(
minimum
),
isTrue
);
expect
(
newDate
.
isAtSameMomentAs
(
maximum
)
||
newDate
.
isBefore
(
maximum
),
isTrue
);
},
initialDateTime:
DateTime
(
2017
,
2
,
28
),
),
),
),
),
);
// 2017 has 28 days in Feb so 29 is greyed out.
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'29'
)).
style
.
color
,
isSameColorAs
(
CupertinoColors
.
inactiveGray
),
);
await
tester
.
drag
(
find
.
text
(
'2017'
),
const
Offset
(
0.0
,
32.0
),
touchSlopY:
0.0
);
await
tester
.
pump
();
await
tester
.
pumpAndSettle
();
// Now the autoscrolling should happen.
expect
(
date
,
DateTime
(
2016
,
2
,
29
),
);
// 2016 has 29 days in Feb so 29 is not greyed out.
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'29'
)).
style
.
color
,
isNot
(
isSameColorAs
(
CupertinoColors
.
inactiveGray
)),
);
await
tester
.
drag
(
find
.
text
(
'2016'
),
const
Offset
(
0.0
,
-
32.0
),
touchSlopY:
0.0
);
await
tester
.
pump
();
// Once to trigger the post frame animate call.
await
tester
.
pumpAndSettle
();
expect
(
date
,
DateTime
(
2017
,
2
,
28
),
);
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'29'
)).
style
.
color
,
isSameColorAs
(
CupertinoColors
.
inactiveGray
),
);
});
testWidgets
(
'picker automatically scrolls away from invalid date on day change'
,
(
WidgetTester
tester
)
async
{
DateTime
date
;
await
tester
.
pumpWidget
(
...
...
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