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
adc64827
Unverified
Commit
adc64827
authored
Jan 03, 2020
by
LongCatIsLooong
Committed by
GitHub
Jan 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement CupertinoDatepicker time/dateTime constraints (#44628)
parent
a3bbdfb2
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
541 additions
and
193 deletions
+541
-193
date_picker.dart
packages/flutter/lib/src/cupertino/date_picker.dart
+386
-192
date_picker_test.dart
packages/flutter/test/cupertino/date_picker_test.dart
+155
-1
No files found.
packages/flutter/lib/src/cupertino/date_picker.dart
View file @
adc64827
This diff is collapsed.
Click to expand it.
packages/flutter/test/cupertino/date_picker_test.dart
View file @
adc64827
...
...
@@ -661,7 +661,7 @@ void main() {
});
testWidgets
(
'picker automatically scrolls away from invalid date, '
'
date
picker automatically scrolls away from invalid date, '
"and onDateTimeChanged doesn't report these dates"
,
(
WidgetTester
tester
)
async
{
DateTime
date
;
...
...
@@ -727,6 +727,160 @@ void main() {
);
});
testWidgets
(
'dateTime picker automatically scrolls away from invalid date, '
"and onDateTimeChanged doesn't report these dates"
,
(
WidgetTester
tester
)
async
{
DateTime
date
;
final
DateTime
minimum
=
DateTime
(
2019
,
11
,
11
,
3
,
30
);
final
DateTime
maximum
=
DateTime
(
2019
,
11
,
11
,
14
,
59
,
59
);
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
Center
(
child:
SizedBox
(
height:
400.0
,
width:
400.0
,
child:
CupertinoDatePicker
(
mode:
CupertinoDatePickerMode
.
dateAndTime
,
minimumDate:
minimum
,
maximumDate:
maximum
,
onDateTimeChanged:
(
DateTime
newDate
)
{
date
=
newDate
;
// Callback doesn't transiently go into invalid dates.
expect
(
minimum
.
isAfter
(
newDate
),
isFalse
);
expect
(
maximum
.
isBefore
(
newDate
),
isFalse
);
},
initialDateTime:
DateTime
(
2019
,
11
,
11
,
4
),
),
),
),
),
);
// 3:00 is valid but 2:00 should be invalid.
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'3'
)).
style
.
color
,
isNot
(
isSameColorAs
(
CupertinoColors
.
inactiveGray
.
color
)),
);
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'2'
)).
style
.
color
,
isSameColorAs
(
CupertinoColors
.
inactiveGray
.
color
),
);
// 'PM' is greyed out.
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'PM'
)).
style
.
color
,
isSameColorAs
(
CupertinoColors
.
inactiveGray
.
color
),
);
await
tester
.
drag
(
find
.
text
(
'AM'
),
const
Offset
(
0.0
,
-
32.0
),
touchSlopY:
0.0
);
await
tester
.
pump
();
await
tester
.
pumpAndSettle
();
// Now the autoscrolling should happen.
expect
(
date
,
DateTime
(
2019
,
11
,
11
,
14
,
59
),
);
// 3'o clock and 'AM' are now greyed out.
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'AM'
)).
style
.
color
,
isSameColorAs
(
CupertinoColors
.
inactiveGray
.
color
),
);
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'3'
)).
style
.
color
,
isSameColorAs
(
CupertinoColors
.
inactiveGray
.
color
),
);
await
tester
.
drag
(
find
.
text
(
'PM'
),
const
Offset
(
0.0
,
32.0
),
touchSlopY:
0.0
);
await
tester
.
pump
();
// Once to trigger the post frame animate call.
await
tester
.
pumpAndSettle
();
// Returns to min date.
expect
(
date
,
DateTime
(
2019
,
11
,
11
,
3
,
30
),
);
});
testWidgets
(
'time picker automatically scrolls away from invalid date, '
"and onDateTimeChanged doesn't report these dates"
,
(
WidgetTester
tester
)
async
{
DateTime
date
;
final
DateTime
minimum
=
DateTime
(
2019
,
11
,
11
,
3
,
30
);
final
DateTime
maximum
=
DateTime
(
2019
,
11
,
11
,
14
,
59
,
59
);
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
Center
(
child:
SizedBox
(
height:
400.0
,
width:
400.0
,
child:
CupertinoDatePicker
(
mode:
CupertinoDatePickerMode
.
time
,
minimumDate:
minimum
,
maximumDate:
maximum
,
onDateTimeChanged:
(
DateTime
newDate
)
{
date
=
newDate
;
// Callback doesn't transiently go into invalid dates.
expect
(
minimum
.
isAfter
(
newDate
),
isFalse
);
expect
(
maximum
.
isBefore
(
newDate
),
isFalse
);
},
initialDateTime:
DateTime
(
2019
,
11
,
11
,
4
),
),
),
),
),
);
// 3:00 is valid but 2:00 should be invalid.
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'3'
)).
style
.
color
,
isNot
(
isSameColorAs
(
CupertinoColors
.
inactiveGray
.
color
)),
);
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'2'
)).
style
.
color
,
isSameColorAs
(
CupertinoColors
.
inactiveGray
.
color
),
);
// 'PM' is greyed out.
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'PM'
)).
style
.
color
,
isSameColorAs
(
CupertinoColors
.
inactiveGray
.
color
),
);
await
tester
.
drag
(
find
.
text
(
'AM'
),
const
Offset
(
0.0
,
-
32.0
),
touchSlopY:
0.0
);
await
tester
.
pump
();
await
tester
.
pumpAndSettle
();
// Now the autoscrolling should happen.
expect
(
date
,
DateTime
(
2019
,
11
,
11
,
14
,
59
),
);
// 3'o clock and 'AM' are now greyed out.
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'AM'
)).
style
.
color
,
isSameColorAs
(
CupertinoColors
.
inactiveGray
.
color
),
);
expect
(
tester
.
widget
<
Text
>(
find
.
text
(
'3'
)).
style
.
color
,
isSameColorAs
(
CupertinoColors
.
inactiveGray
.
color
),
);
await
tester
.
drag
(
find
.
text
(
'PM'
),
const
Offset
(
0.0
,
32.0
),
touchSlopY:
0.0
);
await
tester
.
pump
();
// Once to trigger the post frame animate call.
await
tester
.
pumpAndSettle
();
// Returns to min date.
expect
(
date
,
DateTime
(
2019
,
11
,
11
,
3
,
30
),
);
});
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