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
0a915d6f
Commit
0a915d6f
authored
Jun 30, 2017
by
xster
Committed by
GitHub
Jun 30, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
let the year picker start at the current date instead of the first date (#11042)
parent
d9ca775f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
6 deletions
+28
-6
date_picker.dart
packages/flutter/lib/src/material/date_picker.dart
+11
-0
date_picker_test.dart
packages/flutter/test/material/date_picker_test.dart
+17
-6
No files found.
packages/flutter/lib/src/material/date_picker.dart
View file @
0a915d6f
...
@@ -553,6 +553,16 @@ class YearPicker extends StatefulWidget {
...
@@ -553,6 +553,16 @@ class YearPicker extends StatefulWidget {
class
_YearPickerState
extends
State
<
YearPicker
>
{
class
_YearPickerState
extends
State
<
YearPicker
>
{
static
const
double
_itemExtent
=
50.0
;
static
const
double
_itemExtent
=
50.0
;
ScrollController
scrollController
;
@override
void
initState
()
{
super
.
initState
();
scrollController
=
new
ScrollController
(
// Move the initial scroll position to the currently selected date's year.
initialScrollOffset:
(
widget
.
selectedDate
.
year
-
widget
.
firstDate
.
year
)
*
_itemExtent
,
);
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
...
@@ -560,6 +570,7 @@ class _YearPickerState extends State<YearPicker> {
...
@@ -560,6 +570,7 @@ class _YearPickerState extends State<YearPicker> {
final
ThemeData
themeData
=
Theme
.
of
(
context
);
final
ThemeData
themeData
=
Theme
.
of
(
context
);
final
TextStyle
style
=
themeData
.
textTheme
.
body1
;
final
TextStyle
style
=
themeData
.
textTheme
.
body1
;
return
new
ListView
.
builder
(
return
new
ListView
.
builder
(
controller:
scrollController
,
itemExtent:
_itemExtent
,
itemExtent:
_itemExtent
,
itemCount:
widget
.
lastDate
.
year
-
widget
.
firstDate
.
year
+
1
,
itemCount:
widget
.
lastDate
.
year
-
widget
.
firstDate
.
year
+
1
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
itemBuilder:
(
BuildContext
context
,
int
index
)
{
...
...
packages/flutter/test/material/date_picker_test.dart
View file @
0a915d6f
...
@@ -186,9 +186,9 @@ void main() {
...
@@ -186,9 +186,9 @@ void main() {
await
preparePicker
(
tester
,
(
Future
<
DateTime
>
date
)
async
{
await
preparePicker
(
tester
,
(
Future
<
DateTime
>
date
)
async
{
await
tester
.
tap
(
find
.
text
(
'2016'
));
await
tester
.
tap
(
find
.
text
(
'2016'
));
await
tester
.
pump
();
await
tester
.
pump
();
await
tester
.
tap
(
find
.
text
(
'20
06
'
));
await
tester
.
tap
(
find
.
text
(
'20
18
'
));
await
tester
.
tap
(
find
.
text
(
'OK'
));
await
tester
.
tap
(
find
.
text
(
'OK'
));
expect
(
await
date
,
equals
(
new
DateTime
(
20
06
,
DateTime
.
JANUARY
,
15
)));
expect
(
await
date
,
equals
(
new
DateTime
(
20
18
,
DateTime
.
JANUARY
,
15
)));
});
});
});
});
...
@@ -196,14 +196,25 @@ void main() {
...
@@ -196,14 +196,25 @@ void main() {
await
preparePicker
(
tester
,
(
Future
<
DateTime
>
date
)
async
{
await
preparePicker
(
tester
,
(
Future
<
DateTime
>
date
)
async
{
await
tester
.
tap
(
find
.
text
(
'2016'
));
await
tester
.
tap
(
find
.
text
(
'2016'
));
await
tester
.
pump
();
await
tester
.
pump
();
await
tester
.
tap
(
find
.
text
(
'20
05
'
));
await
tester
.
tap
(
find
.
text
(
'20
17
'
));
await
tester
.
pump
();
await
tester
.
pump
();
final
String
dayLabel
=
new
DateFormat
(
'E, MMM
\
u00a0d'
).
format
(
new
DateTime
(
20
05
,
DateTime
.
JANUARY
,
15
));
final
String
dayLabel
=
new
DateFormat
(
'E, MMM
\
u00a0d'
).
format
(
new
DateTime
(
20
17
,
DateTime
.
JANUARY
,
15
));
await
tester
.
tap
(
find
.
text
(
dayLabel
));
await
tester
.
tap
(
find
.
text
(
dayLabel
));
await
tester
.
pump
();
await
tester
.
pump
();
await
tester
.
tap
(
find
.
text
(
'19'
));
await
tester
.
tap
(
find
.
text
(
'19'
));
await
tester
.
tap
(
find
.
text
(
'OK'
));
await
tester
.
tap
(
find
.
text
(
'OK'
));
expect
(
await
date
,
equals
(
new
DateTime
(
2005
,
DateTime
.
JANUARY
,
19
)));
expect
(
await
date
,
equals
(
new
DateTime
(
2017
,
DateTime
.
JANUARY
,
19
)));
});
});
testWidgets
(
'Current year is initially visible in year picker'
,
(
WidgetTester
tester
)
async
{
initialDate
=
new
DateTime
(
2000
);
firstDate
=
new
DateTime
(
1900
);
lastDate
=
new
DateTime
(
2100
);
await
preparePicker
(
tester
,
(
Future
<
DateTime
>
date
)
async
{
await
tester
.
tap
(
find
.
text
(
'2000'
));
await
tester
.
pump
();
expect
(
find
.
text
(
'2000'
),
findsNWidgets
(
2
));
});
});
});
});
...
@@ -215,7 +226,7 @@ void main() {
...
@@ -215,7 +226,7 @@ void main() {
await
tester
.
tap
(
find
.
text
(
'10'
));
// Earlier than firstDate. Should be ignored.
await
tester
.
tap
(
find
.
text
(
'10'
));
// Earlier than firstDate. Should be ignored.
await
tester
.
tap
(
find
.
text
(
'20'
));
// Later than lastDate. Should be ignored.
await
tester
.
tap
(
find
.
text
(
'20'
));
// Later than lastDate. Should be ignored.
await
tester
.
tap
(
find
.
text
(
'OK'
));
await
tester
.
tap
(
find
.
text
(
'OK'
));
// We should still be on the inital date.
// We should still be on the init
i
al date.
expect
(
await
date
,
equals
(
initialDate
));
expect
(
await
date
,
equals
(
initialDate
));
});
});
});
});
...
...
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