Commit 19cdb21c authored by Venkataramana Neelapala's avatar Venkataramana Neelapala Committed by LongCatIsLooong

Added backgroundColor property to CupertinoTimePicker and CupertinoDatePicker. #34741 (#39056)

parent e31d88f9
......@@ -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: _kBackgroundColor,
backgroundColor: widget.backgroundColor,
squeeze: _kSqueeze,
onSelectedItemChanged: (int index) {
selectedDayFromInitial = index;
......@@ -545,7 +552,7 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
itemExtent: _kItemExtent,
useMagnifier: _kUseMagnifier,
magnification: _kMagnification,
backgroundColor: _kBackgroundColor,
backgroundColor: widget.backgroundColor,
squeeze: _kSqueeze,
onSelectedItemChanged: (int index) {
if (widget.use24hFormat) {
......@@ -599,7 +606,7 @@ class _CupertinoDatePickerDateTimeState extends State<CupertinoDatePicker> {
itemExtent: _kItemExtent,
useMagnifier: _kUseMagnifier,
magnification: _kMagnification,
backgroundColor: _kBackgroundColor,
backgroundColor: widget.backgroundColor,
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: _kBackgroundColor,
backgroundColor: widget.backgroundColor,
squeeze: _kSqueeze,
onSelectedItemChanged: (int index) {
selectedAmPm = index;
......@@ -792,7 +799,7 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
itemExtent: _kItemExtent,
useMagnifier: _kUseMagnifier,
magnification: _kMagnification,
backgroundColor: _kBackgroundColor,
backgroundColor: widget.backgroundColor,
squeeze: _kSqueeze,
onSelectedItemChanged: (int index) {
selectedDay = index + 1;
......@@ -823,7 +830,7 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
itemExtent: _kItemExtent,
useMagnifier: _kUseMagnifier,
magnification: _kMagnification,
backgroundColor: _kBackgroundColor,
backgroundColor: widget.backgroundColor,
squeeze: _kSqueeze,
onSelectedItemChanged: (int index) {
selectedMonth = index + 1;
......@@ -850,7 +857,7 @@ class _CupertinoDatePickerDateState extends State<CupertinoDatePicker> {
offAxisFraction: offAxisFraction,
useMagnifier: _kUseMagnifier,
magnification: _kMagnification,
backgroundColor: _kBackgroundColor,
backgroundColor: widget.backgroundColor,
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: _kBackgroundColor,
backgroundColor: widget.backgroundColor,
squeeze: _kSqueeze,
onSelectedItemChanged: (int index) {
setState(() {
......@@ -1213,7 +1227,7 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
),
offAxisFraction: offAxisFraction,
itemExtent: _kItemExtent,
backgroundColor: _kBackgroundColor,
backgroundColor: widget.backgroundColor,
squeeze: _kSqueeze,
onSelectedItemChanged: (int index) {
setState(() {
......@@ -1326,7 +1340,7 @@ class _CupertinoTimerPickerState extends State<CupertinoTimerPicker> {
),
offAxisFraction: offAxisFraction,
itemExtent: _kItemExtent,
backgroundColor: _kBackgroundColor,
backgroundColor: widget.backgroundColor,
squeeze: _kSqueeze,
onSelectedItemChanged: (int index) {
setState(() {
......
......@@ -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(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment