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
19cdb21c
Commit
19cdb21c
authored
Aug 26, 2019
by
Venkataramana Neelapala
Committed by
LongCatIsLooong
Aug 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added backgroundColor property to CupertinoTimePicker and CupertinoDatePicker. #34741 (#39056)
parent
e31d88f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
11 deletions
+103
-11
date_picker.dart
packages/flutter/lib/src/cupertino/date_picker.dart
+25
-11
date_picker_test.dart
packages/flutter/test/cupertino/date_picker_test.dart
+78
-0
No files found.
packages/flutter/lib/src/cupertino/date_picker.dart
View file @
19cdb21c
...
...
@@ -210,10 +210,12 @@ class CupertinoDatePicker extends StatefulWidget {
this
.
maximumYear
,
this
.
minuteInterval
=
1
,
this
.
use24hFormat
=
false
,
this
.
backgroundColor
=
_kBackgroundColor
})
:
initialDateTime
=
initialDateTime
??
DateTime
.
now
(),
assert
(
mode
!=
null
),
assert
(
onDateTimeChanged
!=
null
),
assert
(
minimumYear
!=
null
),
assert
(
backgroundColor
!=
null
),
assert
(
minuteInterval
>
0
&&
60
%
minuteInterval
==
0
,
'minute interval is not a positive integer factor of 60'
,
...
...
@@ -281,6 +283,11 @@ class CupertinoDatePicker extends StatefulWidget {
/// null.
final
ValueChanged
<
DateTime
>
onDateTimeChanged
;
/// Background color of date picker.
///
/// Defaults to [CupertinoColors.white] when null.
final
Color
backgroundColor
;
@override
State
<
StatefulWidget
>
createState
()
{
// The `time` mode and `dateAndTime` mode of the picker share the time
...
...
@@ -500,7 +507,7 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
itemExtent:
_kItemExtent
,
useMagnifier:
_kUseMagnifier
,
magnification:
_kMagnification
,
backgroundColor:
_kB
ackgroundColor
,
backgroundColor:
widget
.
b
ackgroundColor
,
squeeze:
_kSqueeze
,
onSelectedItemChanged:
(
int
index
)
{
selectedDayFromInitial
=
index
;
...
...
@@ -545,7 +552,7 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
itemExtent:
_kItemExtent
,
useMagnifier:
_kUseMagnifier
,
magnification:
_kMagnification
,
backgroundColor:
_kB
ackgroundColor
,
backgroundColor:
widget
.
b
ackgroundColor
,
squeeze:
_kSqueeze
,
onSelectedItemChanged:
(
int
index
)
{
if
(
widget
.
use24hFormat
)
{
...
...
@@ -599,7 +606,7 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
itemExtent:
_kItemExtent
,
useMagnifier:
_kUseMagnifier
,
magnification:
_kMagnification
,
backgroundColor:
_kB
ackgroundColor
,
backgroundColor:
widget
.
b
ackgroundColor
,
squeeze:
_kSqueeze
,
onSelectedItemChanged:
(
int
index
)
{
selectedMinute
=
index
*
widget
.
minuteInterval
;
...
...
@@ -627,7 +634,7 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
itemExtent:
_kItemExtent
,
useMagnifier:
_kUseMagnifier
,
magnification:
_kMagnification
,
backgroundColor:
_kB
ackgroundColor
,
backgroundColor:
widget
.
b
ackgroundColor
,
squeeze:
_kSqueeze
,
onSelectedItemChanged:
(
int
index
)
{
selectedAmPm
=
index
;
...
...
@@ -792,7 +799,7 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
itemExtent:
_kItemExtent
,
useMagnifier:
_kUseMagnifier
,
magnification:
_kMagnification
,
backgroundColor:
_kB
ackgroundColor
,
backgroundColor:
widget
.
b
ackgroundColor
,
squeeze:
_kSqueeze
,
onSelectedItemChanged:
(
int
index
)
{
selectedDay
=
index
+
1
;
...
...
@@ -823,7 +830,7 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
itemExtent:
_kItemExtent
,
useMagnifier:
_kUseMagnifier
,
magnification:
_kMagnification
,
backgroundColor:
_kB
ackgroundColor
,
backgroundColor:
widget
.
b
ackgroundColor
,
squeeze:
_kSqueeze
,
onSelectedItemChanged:
(
int
index
)
{
selectedMonth
=
index
+
1
;
...
...
@@ -850,7 +857,7 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
offAxisFraction:
offAxisFraction
,
useMagnifier:
_kUseMagnifier
,
magnification:
_kMagnification
,
backgroundColor:
_kB
ackgroundColor
,
backgroundColor:
widget
.
b
ackgroundColor
,
onSelectedItemChanged:
(
int
index
)
{
selectedYear
=
index
;
if
(
DateTime
(
selectedYear
,
selectedMonth
,
selectedDay
).
day
==
selectedDay
)
...
...
@@ -1051,6 +1058,7 @@ class CupertinoTimerPicker extends StatefulWidget {
this
.
initialTimerDuration
=
Duration
.
zero
,
this
.
minuteInterval
=
1
,
this
.
secondInterval
=
1
,
this
.
backgroundColor
=
_kBackgroundColor
,
@required
this
.
onTimerDurationChanged
,
})
:
assert
(
mode
!=
null
),
assert
(
onTimerDurationChanged
!=
null
),
...
...
@@ -1059,7 +1067,8 @@ class CupertinoTimerPicker extends StatefulWidget {
assert
(
minuteInterval
>
0
&&
60
%
minuteInterval
==
0
),
assert
(
secondInterval
>
0
&&
60
%
secondInterval
==
0
),
assert
(
initialTimerDuration
.
inMinutes
%
minuteInterval
==
0
),
assert
(
initialTimerDuration
.
inSeconds
%
secondInterval
==
0
);
assert
(
initialTimerDuration
.
inSeconds
%
secondInterval
==
0
),
assert
(
backgroundColor
!=
null
);
/// The mode of the timer picker.
final
CupertinoTimerPickerMode
mode
;
...
...
@@ -1078,6 +1087,11 @@ class CupertinoTimerPicker extends StatefulWidget {
/// Callback called when the timer duration changes.
final
ValueChanged
<
Duration
>
onTimerDurationChanged
;
/// Background color of timer picker.
///
/// Defaults to [CupertinoColors.white] when null.
final
Color
backgroundColor
;
@override
State
<
StatefulWidget
>
createState
()
=>
_CupertinoTimerPickerState
();
}
...
...
@@ -1134,7 +1148,7 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
scrollController:
FixedExtentScrollController
(
initialItem:
selectedHour
),
offAxisFraction:
-
0.5
*
textDirectionFactor
,
itemExtent:
_kItemExtent
,
backgroundColor:
_kB
ackgroundColor
,
backgroundColor:
widget
.
b
ackgroundColor
,
squeeze:
_kSqueeze
,
onSelectedItemChanged:
(
int
index
)
{
setState
(()
{
...
...
@@ -1213,7 +1227,7 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
),
offAxisFraction:
offAxisFraction
,
itemExtent:
_kItemExtent
,
backgroundColor:
_kB
ackgroundColor
,
backgroundColor:
widget
.
b
ackgroundColor
,
squeeze:
_kSqueeze
,
onSelectedItemChanged:
(
int
index
)
{
setState
(()
{
...
...
@@ -1326,7 +1340,7 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
),
offAxisFraction:
offAxisFraction
,
itemExtent:
_kItemExtent
,
backgroundColor:
_kB
ackgroundColor
,
backgroundColor:
widget
.
b
ackgroundColor
,
squeeze:
_kSqueeze
,
onSelectedItemChanged:
(
int
index
)
{
setState
(()
{
...
...
packages/flutter/test/cupertino/date_picker_test.dart
View file @
19cdb21c
...
...
@@ -104,6 +104,45 @@ void main() {
);
});
testWidgets
(
'background color default value'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
CupertinoTimerPicker
(
onTimerDurationChanged:
(
_
)
{
},
),
),
);
final
Iterable
<
CupertinoPicker
>
pickers
=
tester
.
allWidgets
.
whereType
<
CupertinoPicker
>();
expect
(
pickers
.
any
((
CupertinoPicker
picker
)
=>
picker
.
backgroundColor
!=
CupertinoColors
.
white
),
false
);
});
testWidgets
(
'background color is not null'
,
(
WidgetTester
tester
)
async
{
expect
(
()
{
CupertinoTimerPicker
(
onTimerDurationChanged:
(
_
)
{
},
backgroundColor:
null
,
);
},
throwsAssertionError
,
);
});
testWidgets
(
'specified background color is applied'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
CupertinoTimerPicker
(
onTimerDurationChanged:
(
_
)
{
},
backgroundColor:
CupertinoColors
.
black
,
),
),
);
final
Iterable
<
CupertinoPicker
>
pickers
=
tester
.
allWidgets
.
whereType
<
CupertinoPicker
>();
expect
(
pickers
.
any
((
CupertinoPicker
picker
)
=>
picker
.
backgroundColor
!=
CupertinoColors
.
black
),
false
);
});
testWidgets
(
'columns are ordered correctly when text direction is ltr'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
CupertinoApp
(
...
...
@@ -265,6 +304,45 @@ void main() {
expect
(
picker
.
initialDateTime
,
isNotNull
);
});
testWidgets
(
'background color default value'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
CupertinoDatePicker
(
onDateTimeChanged:
(
_
)
{
},
),
),
);
final
Iterable
<
CupertinoPicker
>
pickers
=
tester
.
allWidgets
.
whereType
<
CupertinoPicker
>();
expect
(
pickers
.
any
((
CupertinoPicker
picker
)
=>
picker
.
backgroundColor
!=
CupertinoColors
.
white
),
false
);
});
testWidgets
(
'background color is not null'
,
(
WidgetTester
tester
)
async
{
expect
(
()
{
CupertinoDatePicker
(
onDateTimeChanged:
(
_
)
{
},
backgroundColor:
null
,
);
},
throwsAssertionError
,
);
});
testWidgets
(
'specified background color is applied'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
CupertinoApp
(
home:
CupertinoDatePicker
(
onDateTimeChanged:
(
_
)
{
},
backgroundColor:
CupertinoColors
.
black
,
),
),
);
final
Iterable
<
CupertinoPicker
>
pickers
=
tester
.
allWidgets
.
whereType
<
CupertinoPicker
>();
expect
(
pickers
.
any
((
CupertinoPicker
picker
)
=>
picker
.
backgroundColor
!=
CupertinoColors
.
black
),
false
);
});
testWidgets
(
'initial date honors minuteInterval'
,
(
WidgetTester
tester
)
async
{
DateTime
newDateTime
;
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