diff --git a/bin/internal/goldens.version b/bin/internal/goldens.version index 6324af9a53..c6c5ed784e 100644 --- a/bin/internal/goldens.version +++ b/bin/internal/goldens.version @@ -1 +1 @@ -d19eee409dcf3348dea030b374e53a86f79b7de7 +0728c1b6e968602e173d0153a88d9cfb932d8c9b diff --git a/packages/flutter/lib/src/cupertino/date_picker.dart b/packages/flutter/lib/src/cupertino/date_picker.dart index 33b26ed022..9ef910d86c 100644 --- a/packages/flutter/lib/src/cupertino/date_picker.dart +++ b/packages/flutter/lib/src/cupertino/date_picker.dart @@ -24,6 +24,8 @@ const double _kDatePickerPadSize = 12.0; // The density of a date picker is different from a generic picker. // Eyeballed from iOS. const double _kSqueeze = 1.25; +// Considers setting the default background color from the theme, in the future. +const Color _kBackgroundColor = CupertinoColors.white; const TextStyle _kDefaultPickerTextStyle = TextStyle( letterSpacing: -0.83, @@ -225,11 +227,12 @@ class CupertinoDatePicker extends StatefulWidget { this.maximumYear, this.minuteInterval = 1, this.use24hFormat = false, - this.backgroundColor, + 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', @@ -299,7 +302,7 @@ class CupertinoDatePicker extends StatefulWidget { /// Background color of date picker. /// - /// Defaults to null, which disables background painting entirely. + /// Defaults to [CupertinoColors.white] when null. final Color backgroundColor; @override @@ -1118,7 +1121,7 @@ class CupertinoTimerPicker extends StatefulWidget { this.minuteInterval = 1, this.secondInterval = 1, this.alignment = Alignment.center, - this.backgroundColor, + this.backgroundColor = _kBackgroundColor, @required this.onTimerDurationChanged, }) : assert(mode != null), assert(onTimerDurationChanged != null), @@ -1128,6 +1131,7 @@ class CupertinoTimerPicker extends StatefulWidget { assert(secondInterval > 0 && 60 % secondInterval == 0), assert(initialTimerDuration.inMinutes % minuteInterval == 0), assert(initialTimerDuration.inSeconds % secondInterval == 0), + assert(backgroundColor != null), assert(alignment != null), super(key: key); @@ -1155,7 +1159,7 @@ class CupertinoTimerPicker extends StatefulWidget { /// Background color of timer picker. /// - /// Defaults to null, which disables background painting entirely. + /// Defaults to [CupertinoColors.white] when null. final Color backgroundColor; @override @@ -1562,7 +1566,7 @@ class _CupertinoTimerPickerState extends State { child: Align( alignment: widget.alignment, child: Container( - color: CupertinoDynamicColor.resolve(widget.backgroundColor, context), + color: _kBackgroundColor, width: totalWidth, height: _kPickerHeight, child: DefaultTextStyle( diff --git a/packages/flutter/lib/src/cupertino/picker.dart b/packages/flutter/lib/src/cupertino/picker.dart index 3527edd5ed..080cca09cd 100644 --- a/packages/flutter/lib/src/cupertino/picker.dart +++ b/packages/flutter/lib/src/cupertino/picker.dart @@ -7,23 +7,19 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; -import 'colors.dart'; import 'theme.dart'; /// Color of the 'magnifier' lens border. -const Color _kHighlighterBorder = CupertinoDynamicColor.withBrightness( - color: Color(0x33000000), - darkColor: Color(0x33FFFFFF), -); +const Color _kHighlighterBorder = Color(0xFF7F7F7F); +const Color _kDefaultBackground = Color(0xFFD2D4DB); // Eyeballed values comparing with a native picker to produce the right // curvatures and densities. const double _kDefaultDiameterRatio = 1.07; const double _kDefaultPerspective = 0.003; const double _kSqueeze = 1.45; - -// Opacity fraction value that dims the wheel above and below the "magnifier" -// lens. -const double _kOverAndUnderCenterOpacity = 0.447; +/// Opacity fraction value that hides the wheel above and below the 'magnifier' +/// lens with the same color as the background. +const double _kForegroundScreenOpacityFraction = 0.7; /// An iOS-styled picker. /// @@ -65,7 +61,7 @@ class CupertinoPicker extends StatefulWidget { CupertinoPicker({ Key key, this.diameterRatio = _kDefaultDiameterRatio, - this.backgroundColor, + this.backgroundColor = _kDefaultBackground, this.offAxisFraction = 0.0, this.useMagnifier = false, this.magnification = 1.0, @@ -108,7 +104,7 @@ class CupertinoPicker extends StatefulWidget { CupertinoPicker.builder({ Key key, this.diameterRatio = _kDefaultDiameterRatio, - this.backgroundColor, + this.backgroundColor = _kDefaultBackground, this.offAxisFraction = 0.0, this.useMagnifier = false, this.magnification = 1.0, @@ -243,32 +239,110 @@ class _CupertinoPickerState extends State { } } - /// Draws the magnifier borders. - Widget _buildMagnifierScreen() { - final Color resolvedBorderColor = CupertinoDynamicColor.resolve(_kHighlighterBorder, context); + /// Makes the fade to [CupertinoPicker.backgroundColor] edge gradients. + Widget _buildGradientScreen() { + // Because BlendMode.dstOut doesn't work correctly with BoxDecoration we + // have to just do a color blend. And a due to the way we are layering + // the magnifier and the gradient on the background, using a transparent + // background color makes the picker look odd. + if (widget.backgroundColor != null && widget.backgroundColor.alpha < 255) + return Container(); - return IgnorePointer( - child: Center( + final Color widgetBackgroundColor = widget.backgroundColor ?? const Color(0xFFFFFFFF); + return Positioned.fill( + child: IgnorePointer( child: Container( decoration: BoxDecoration( - border: Border( - top: BorderSide(width: 0.0, color: resolvedBorderColor), - bottom: BorderSide(width: 0.0, color: resolvedBorderColor), + gradient: LinearGradient( + colors: [ + widgetBackgroundColor, + widgetBackgroundColor.withAlpha(0xF2), + widgetBackgroundColor.withAlpha(0xDD), + widgetBackgroundColor.withAlpha(0), + widgetBackgroundColor.withAlpha(0), + widgetBackgroundColor.withAlpha(0xDD), + widgetBackgroundColor.withAlpha(0xF2), + widgetBackgroundColor, + ], + stops: const [ + 0.0, 0.05, 0.09, 0.22, 0.78, 0.91, 0.95, 1.0, + ], + begin: Alignment.topCenter, + end: Alignment.bottomCenter, ), ), - constraints: BoxConstraints.expand( - height: widget.itemExtent * widget.magnification, - ), ), ), ); } + /// Makes the magnifier lens look so that the colors are normal through + /// the lens and partially grayed out around it. + Widget _buildMagnifierScreen() { + final Color foreground = widget.backgroundColor?.withAlpha( + (widget.backgroundColor.alpha * _kForegroundScreenOpacityFraction).toInt() + ); + + return IgnorePointer( + child: Column( + children: [ + Expanded( + child: Container( + color: foreground, + ), + ), + Container( + decoration: const BoxDecoration( + border: Border( + top: BorderSide(width: 0.0, color: _kHighlighterBorder), + bottom: BorderSide(width: 0.0, color: _kHighlighterBorder), + ), + ), + constraints: BoxConstraints.expand( + height: widget.itemExtent * widget.magnification, + ), + ), + Expanded( + child: Container( + color: foreground, + ), + ), + ], + ), + ); + } + + Widget _buildUnderMagnifierScreen() { + final Color foreground = widget.backgroundColor?.withAlpha( + (widget.backgroundColor.alpha * _kForegroundScreenOpacityFraction).toInt() + ); + + return Column( + children: [ + Expanded(child: Container()), + Container( + color: foreground, + constraints: BoxConstraints.expand( + height: widget.itemExtent * widget.magnification, + ), + ), + Expanded(child: Container()), + ], + ); + } + + Widget _addBackgroundToChild(Widget child) { + return DecoratedBox( + decoration: BoxDecoration( + color: widget.backgroundColor, + ), + child: child, + ); + } + @override Widget build(BuildContext context) { - final Color resolvedBackgroundColor = CupertinoDynamicColor.resolve(widget.backgroundColor, context); - - final Widget result = DefaultTextStyle( + Widget result = DefaultTextStyle( style: CupertinoTheme.of(context).textTheme.pickerTextStyle, child: Stack( children: [ @@ -283,7 +357,6 @@ class _CupertinoPickerState extends State { offAxisFraction: widget.offAxisFraction, useMagnifier: widget.useMagnifier, magnification: widget.magnification, - overAndUnderCenterOpacity: _kOverAndUnderCenterOpacity, itemExtent: widget.itemExtent, squeeze: widget.squeeze, onSelectedItemChanged: _handleSelectedItemChanged, @@ -291,15 +364,24 @@ class _CupertinoPickerState extends State { ), ), ), + _buildGradientScreen(), _buildMagnifierScreen(), ], ), ); - - return DecoratedBox( - decoration: BoxDecoration(color: resolvedBackgroundColor), - child: result, - ); + // Adds the appropriate opacity under the magnifier if the background + // color is transparent. + if (widget.backgroundColor != null && widget.backgroundColor.alpha < 255) { + result = Stack( + children: [ + _buildUnderMagnifierScreen(), + _addBackgroundToChild(result), + ], + ); + } else { + result = _addBackgroundToChild(result); + } + return result; } } diff --git a/packages/flutter/lib/src/rendering/list_wheel_viewport.dart b/packages/flutter/lib/src/rendering/list_wheel_viewport.dart index 406f5aa98d..8a12509a7c 100644 --- a/packages/flutter/lib/src/rendering/list_wheel_viewport.dart +++ b/packages/flutter/lib/src/rendering/list_wheel_viewport.dart @@ -140,7 +140,6 @@ class RenderListWheelViewport double offAxisFraction = 0, bool useMagnifier = false, double magnification = 1, - double overAndUnderCenterOpacity = 1, @required double itemExtent, double squeeze = 1, bool clipToSize = true, @@ -157,8 +156,6 @@ class RenderListWheelViewport assert(useMagnifier != null), assert(magnification != null), assert(magnification > 0), - assert(overAndUnderCenterOpacity != null), - assert(overAndUnderCenterOpacity >= 0 && overAndUnderCenterOpacity <= 1), assert(itemExtent != null), assert(squeeze != null), assert(squeeze > 0), @@ -175,7 +172,6 @@ class RenderListWheelViewport _offAxisFraction = offAxisFraction, _useMagnifier = useMagnifier, _magnification = magnification, - _overAndUnderCenterOpacity = overAndUnderCenterOpacity, _itemExtent = itemExtent, _squeeze = squeeze, _clipToSize = clipToSize, @@ -372,25 +368,6 @@ class RenderListWheelViewport markNeedsPaint(); } - /// {@template flutter.rendering.wheelList.overAndUnderCenterOpacity} - /// The opacity value that will be applied to the wheel that appears below and - /// above the magnifier. - /// - /// The default value is 1.0, which will not change anything. - /// - /// Must be greater than or equal to 0, and less than or equal to 1. - /// {@endtemplate} - double get overAndUnderCenterOpacity => _overAndUnderCenterOpacity; - double _overAndUnderCenterOpacity = 1.0; - set overAndUnderCenterOpacity(double value) { - assert(value != null); - assert(value >= 0 && value <= 1); - if (value == _overAndUnderCenterOpacity) - return; - _overAndUnderCenterOpacity = value; - markNeedsPaint(); - } - /// {@template flutter.rendering.wheelList.itemExtent} /// The size of the children along the main axis. Children [RenderBox]es will /// be given the [BoxConstraints] of this exact size. @@ -845,16 +822,20 @@ class RenderListWheelViewport // Offset that helps painting everything in the center (e.g. angle = 0). final Offset offsetToCenter = Offset( - untransformedPaintingCoordinates.dx, - -_topScrollMarginExtent - ); + untransformedPaintingCoordinates.dx, + -_topScrollMarginExtent); - final bool shouldApplyOffCenterDim = overAndUnderCenterOpacity < 1; - if (useMagnifier || shouldApplyOffCenterDim) { - _paintChildWithMagnifier(context, offset, child, transform, offsetToCenter, untransformedPaintingCoordinates); - } else { + if (!useMagnifier) _paintChildCylindrically(context, offset, child, transform, offsetToCenter); - } + else + _paintChildWithMagnifier( + context, + offset, + child, + transform, + offsetToCenter, + untransformedPaintingCoordinates, + ); } /// Paint child with the magnifier active - the child will be rendered @@ -897,34 +878,36 @@ class RenderListWheelViewport // Clipping the part in the center. context.pushClipRect( - needsCompositing, - offset, - centerRect, - (PaintingContext context, Offset offset) { - context.pushTransform( - needsCompositing, - offset, - _magnifyTransform(), - (PaintingContext context, Offset offset) { - context.paintChild(child, offset + untransformedPaintingCoordinates); + false, + offset, + centerRect, + (PaintingContext context, Offset offset) { + context.pushTransform( + false, + offset, + _magnifyTransform(), + (PaintingContext context, Offset offset) { + context.paintChild( + child, + offset + untransformedPaintingCoordinates); + }); }); - }); // Clipping the part in either the top-half or bottom-half of the wheel. context.pushClipRect( - needsCompositing, - offset, - untransformedPaintingCoordinates.dy <= magnifierTopLinePosition - ? topHalfRect - : bottomHalfRect, - (PaintingContext context, Offset offset) { - _paintChildCylindrically( - context, - offset, - child, - cylindricalTransform, - offsetToCenter); - }, + false, + offset, + untransformedPaintingCoordinates.dy <= magnifierTopLinePosition + ? topHalfRect + : bottomHalfRect, + (PaintingContext context, Offset offset) { + _paintChildCylindrically( + context, + offset, + child, + cylindricalTransform, + offsetToCenter); + }, ); } else { _paintChildCylindrically( @@ -944,26 +927,20 @@ class RenderListWheelViewport Matrix4 cylindricalTransform, Offset offsetToCenter, ) { - // Paint child with cylindrically. - final PaintingContextCallback painter = (PaintingContext context, Offset offset) { - context.paintChild( - child, - // Paint everything in the center (e.g. angle = 0), then transform. - offset + offsetToCenter, - ); - }; - - // Paint child with cylindrically, with [overAndUnderCenterOpacity]. - final PaintingContextCallback opacityPainter = (PaintingContext context, Offset offset) { - context.pushOpacity(offset, (overAndUnderCenterOpacity * 255).round(), painter); - }; - context.pushTransform( - needsCompositing, + // Text with TransformLayers and no cullRects currently have an issue rendering + // https://github.com/flutter/flutter/issues/14224. + false, offset, _centerOriginTransform(cylindricalTransform), // Pre-transform painting function. - overAndUnderCenterOpacity == 1 ? painter : opacityPainter, + (PaintingContext context, Offset offset) { + context.paintChild( + child, + // Paint everything in the center (e.g. angle = 0), then transform. + offset + offsetToCenter, + ); + }, ); } diff --git a/packages/flutter/lib/src/widgets/list_wheel_scroll_view.dart b/packages/flutter/lib/src/widgets/list_wheel_scroll_view.dart index 719baa121a..2500e1aae7 100644 --- a/packages/flutter/lib/src/widgets/list_wheel_scroll_view.dart +++ b/packages/flutter/lib/src/widgets/list_wheel_scroll_view.dart @@ -574,7 +574,6 @@ class ListWheelScrollView extends StatefulWidget { this.offAxisFraction = 0.0, this.useMagnifier = false, this.magnification = 1.0, - this.overAndUnderCenterOpacity = 1.0, @required this.itemExtent, this.squeeze = 1.0, this.onSelectedItemChanged, @@ -588,8 +587,6 @@ class ListWheelScrollView extends StatefulWidget { assert(perspective > 0), assert(perspective <= 0.01, RenderListWheelViewport.perspectiveTooHighMessage), assert(magnification > 0), - assert(overAndUnderCenterOpacity != null), - assert(overAndUnderCenterOpacity >= 0 && overAndUnderCenterOpacity <= 1), assert(itemExtent != null), assert(itemExtent > 0), assert(squeeze != null), @@ -614,7 +611,6 @@ class ListWheelScrollView extends StatefulWidget { this.offAxisFraction = 0.0, this.useMagnifier = false, this.magnification = 1.0, - this.overAndUnderCenterOpacity = 1.0, @required this.itemExtent, this.squeeze = 1.0, this.onSelectedItemChanged, @@ -628,8 +624,6 @@ class ListWheelScrollView extends StatefulWidget { assert(perspective > 0), assert(perspective <= 0.01, RenderListWheelViewport.perspectiveTooHighMessage), assert(magnification > 0), - assert(overAndUnderCenterOpacity != null), - assert(overAndUnderCenterOpacity >= 0 && overAndUnderCenterOpacity <= 1), assert(itemExtent != null), assert(itemExtent > 0), assert(squeeze != null), @@ -682,9 +676,6 @@ class ListWheelScrollView extends StatefulWidget { /// {@macro flutter.rendering.wheelList.magnification} final double magnification; - /// {@macro flutter.rendering.wheelList.overAndUnderCenterOpacity} - final double overAndUnderCenterOpacity; - /// Size of each child in the main axis. Must not be null and must be /// positive. final double itemExtent; @@ -765,7 +756,6 @@ class _ListWheelScrollViewState extends State { offAxisFraction: widget.offAxisFraction, useMagnifier: widget.useMagnifier, magnification: widget.magnification, - overAndUnderCenterOpacity: widget.overAndUnderCenterOpacity, itemExtent: widget.itemExtent, squeeze: widget.squeeze, clipToSize: widget.clipToSize, @@ -961,7 +951,6 @@ class ListWheelViewport extends RenderObjectWidget { this.offAxisFraction = 0.0, this.useMagnifier = false, this.magnification = 1.0, - this.overAndUnderCenterOpacity = 1.0, @required this.itemExtent, this.squeeze = 1.0, this.clipToSize = true, @@ -975,8 +964,6 @@ class ListWheelViewport extends RenderObjectWidget { assert(perspective != null), assert(perspective > 0), assert(perspective <= 0.01, RenderListWheelViewport.perspectiveTooHighMessage), - assert(overAndUnderCenterOpacity != null), - assert(overAndUnderCenterOpacity >= 0 && overAndUnderCenterOpacity <= 1), assert(itemExtent != null), assert(itemExtent > 0), assert(squeeze != null), @@ -1004,9 +991,6 @@ class ListWheelViewport extends RenderObjectWidget { /// {@macro flutter.rendering.wheelList.magnification} final double magnification; - /// {@macro flutter.rendering.wheelList.overAndUnderCenterOpacity} - final double overAndUnderCenterOpacity; - /// {@macro flutter.rendering.wheelList.itemExtent} final double itemExtent; @@ -1042,7 +1026,6 @@ class ListWheelViewport extends RenderObjectWidget { offAxisFraction: offAxisFraction, useMagnifier: useMagnifier, magnification: magnification, - overAndUnderCenterOpacity: overAndUnderCenterOpacity, itemExtent: itemExtent, squeeze: squeeze, clipToSize: clipToSize, @@ -1059,7 +1042,6 @@ class ListWheelViewport extends RenderObjectWidget { ..offAxisFraction = offAxisFraction ..useMagnifier = useMagnifier ..magnification = magnification - ..overAndUnderCenterOpacity = overAndUnderCenterOpacity ..itemExtent = itemExtent ..squeeze = squeeze ..clipToSize = clipToSize diff --git a/packages/flutter/test/cupertino/date_picker_test.dart b/packages/flutter/test/cupertino/date_picker_test.dart index 75ab2f8a5d..328b4738e1 100644 --- a/packages/flutter/test/cupertino/date_picker_test.dart +++ b/packages/flutter/test/cupertino/date_picker_test.dart @@ -115,20 +115,19 @@ void main() { ); final Iterable pickers = tester.allWidgets.whereType(); - expect(pickers.any((CupertinoPicker picker) => picker.backgroundColor != null), false); + expect(pickers.any((CupertinoPicker picker) => picker.backgroundColor != CupertinoColors.white), false); }); - testWidgets('background color can be null', (WidgetTester tester) async { - await tester.pumpWidget( - CupertinoApp( - home: CupertinoTimerPicker( + testWidgets('background color is not null', (WidgetTester tester) async { + expect( + () { + CupertinoTimerPicker( onTimerDurationChanged: (_) { }, backgroundColor: null, - ), - ), + ); + }, + throwsAssertionError, ); - - expect(tester.takeException(), isNull); }); testWidgets('specified background color is applied', (WidgetTester tester) async { @@ -316,20 +315,19 @@ void main() { ); final Iterable pickers = tester.allWidgets.whereType(); - expect(pickers.any((CupertinoPicker picker) => picker.backgroundColor != null), false); + expect(pickers.any((CupertinoPicker picker) => picker.backgroundColor != CupertinoColors.white), false); }); - testWidgets('background color can be null', (WidgetTester tester) async { - await tester.pumpWidget( - CupertinoApp( - home: CupertinoDatePicker( + testWidgets('background color is not null', (WidgetTester tester) async { + expect( + () { + CupertinoDatePicker( onDateTimeChanged: (_) { }, backgroundColor: null, - ), - ), + ); + }, + throwsAssertionError, ); - - expect(tester.takeException(), isNull); }); testWidgets('specified background color is applied', (WidgetTester tester) async { @@ -926,7 +924,7 @@ void main() { find.byType(CupertinoDatePicker), matchesGoldenFile( 'date_picker_test.datetime.initial.png', - version: 3, + version: 2, ), ); @@ -938,7 +936,7 @@ void main() { find.byType(CupertinoDatePicker), matchesGoldenFile( 'date_picker_test.datetime.drag.png', - version: 3, + version: 2, ), ); }); @@ -975,7 +973,7 @@ void main() { find.byType(CupertinoTimerPicker), matchesGoldenFile( 'timer_picker_test.datetime.initial.png', - version: 2, + version: 1, ), ); @@ -987,7 +985,7 @@ void main() { find.byType(CupertinoTimerPicker), matchesGoldenFile( 'timer_picker_test.datetime.drag.png', - version: 2, + version: 1, ), ); }); diff --git a/packages/flutter/test/cupertino/picker_test.dart b/packages/flutter/test/cupertino/picker_test.dart index cd7060eaad..cba11acd21 100644 --- a/packages/flutter/test/cupertino/picker_test.dart +++ b/packages/flutter/test/cupertino/picker_test.dart @@ -7,8 +7,6 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import '../rendering/mock_canvas.dart'; - void main() { testWidgets('Picker respects theme styling', (WidgetTester tester) async { await tester.pumpWidget( @@ -95,56 +93,125 @@ void main() { }); }); - testWidgets('picker dark mode', (WidgetTester tester) async { - await tester.pumpWidget( - CupertinoApp( - theme: const CupertinoThemeData(brightness: Brightness.light), - home: Align( - alignment: Alignment.topLeft, - child: SizedBox( - height: 300.0, - width: 300.0, - child: CupertinoPicker( - backgroundColor: const CupertinoDynamicColor.withBrightness( - color: Color(0xFF123456), // Set alpha channel to FF to disable under magnifier painting. - darkColor: Color(0xFF654321), + group('gradient', () { + testWidgets('gradient displays correctly with background color', (WidgetTester tester) async { + const Color backgroundColor = Color.fromRGBO(255, 0, 0, 1.0); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + height: 300.0, + width: 300.0, + child: CupertinoPicker( + backgroundColor: backgroundColor, + itemExtent: 15.0, + children: const [ + Text('1'), + Text('1'), + Text('1'), + Text('1'), + Text('1'), + Text('1'), + Text('1'), + ], + onSelectedItemChanged: (int i) { }, ), - itemExtent: 15.0, - children: const [Text('1'), Text('1')], - onSelectedItemChanged: (int i) { }, ), ), ), - ), - ); + ); + final Container container = tester.firstWidget(find.byType(Container)); + final BoxDecoration boxDecoration = container.decoration; + expect(boxDecoration.gradient.colors, [ + backgroundColor, + backgroundColor.withAlpha(0xF2), + backgroundColor.withAlpha(0xDD), + backgroundColor.withAlpha(0x00), + backgroundColor.withAlpha(0x00), + backgroundColor.withAlpha(0xDD), + backgroundColor.withAlpha(0xF2), + backgroundColor, + ]); + }); - expect(find.byType(CupertinoPicker), paints..path(color: const Color(0x33000000), style: PaintingStyle.stroke)); - expect(find.byType(CupertinoPicker), paints..rect(color: const Color(0xFF123456))); - - await tester.pumpWidget( - CupertinoApp( - theme: const CupertinoThemeData(brightness: Brightness.dark), - home: Align( - alignment: Alignment.topLeft, - child: SizedBox( - height: 300.0, - width: 300.0, - child: CupertinoPicker( - backgroundColor: const CupertinoDynamicColor.withBrightness( - color: Color(0xFF123456), - darkColor: Color(0xFF654321), + testWidgets('No gradient displays with transparent background color', (WidgetTester tester) async { + const Color backgroundColor = Color.fromRGBO(255, 0, 0, 0.5); + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + height: 300.0, + width: 300.0, + child: CupertinoPicker( + backgroundColor: backgroundColor, + itemExtent: 15.0, + children: const [ + Text('1'), + Text('1'), + Text('1'), + Text('1'), + Text('1'), + Text('1'), + Text('1'), + ], + onSelectedItemChanged: (int i) { }, ), - itemExtent: 15.0, - children: const [Text('1'), Text('1')], - onSelectedItemChanged: (int i) { }, ), ), ), - ), - ); + ); + final DecoratedBox decoratedBox = tester.firstWidget(find.byType(DecoratedBox)); + final BoxDecoration boxDecoration = decoratedBox.decoration; + expect(boxDecoration.gradient, isNull); + expect(boxDecoration.color, isNotNull); + }); - expect(find.byType(CupertinoPicker), paints..path(color: const Color(0x33FFFFFF), style: PaintingStyle.stroke)); - expect(find.byType(CupertinoPicker), paints..rect(color: const Color(0xFF654321))); + testWidgets('gradient displays correctly with null background color', (WidgetTester tester) async { + await tester.pumpWidget( + Directionality( + textDirection: TextDirection.ltr, + child: Align( + alignment: Alignment.topLeft, + child: SizedBox( + height: 300.0, + width: 300.0, + child: CupertinoPicker( + backgroundColor: null, + itemExtent: 15.0, + children: const [ + Text('1'), + Text('1'), + Text('1'), + Text('1'), + Text('1'), + Text('1'), + Text('1'), + ], + onSelectedItemChanged: (int i) { }, + ), + ), + ), + ), + ); + // If the background color is null, the gradient color should be white. + const Color backgroundColor = Color(0xFFFFFFFF); + final Container container = tester.firstWidget(find.byType(Container)); + final BoxDecoration boxDecoration = container.decoration; + expect(boxDecoration.gradient.colors, [ + backgroundColor, + backgroundColor.withAlpha(0xF2), + backgroundColor.withAlpha(0xDD), + backgroundColor.withAlpha(0x00), + backgroundColor.withAlpha(0x00), + backgroundColor.withAlpha(0xDD), + backgroundColor.withAlpha(0xF2), + backgroundColor, + ]); + }); }); group('scroll', () { diff --git a/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart b/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart index 229406bfcc..b52e5388b8 100644 --- a/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart +++ b/packages/flutter/test/widgets/list_wheel_scroll_view_test.dart @@ -64,63 +64,6 @@ void main() { throwsAssertionError, ); }); - - testWidgets('ListWheelScrollView needs valid overAndUnderCenterOpacity', (WidgetTester tester) async { - expect( - () { - ListWheelScrollView( - overAndUnderCenterOpacity: null, - itemExtent: 20.0, - children: [Container()], - ); - }, - throwsAssertionError, - ); - - expect( - () { - ListWheelScrollView( - overAndUnderCenterOpacity: -1, - itemExtent: 20.0, - children: [Container()], - ); - }, - throwsAssertionError, - ); - - expect( - () { - ListWheelScrollView( - overAndUnderCenterOpacity: 2, - itemExtent: 20.0, - children: [Container()], - ); - }, - throwsAssertionError, - ); - - expect( - () { - ListWheelScrollView( - overAndUnderCenterOpacity: 1, - itemExtent: 20.0, - children: [Container()], - ); - }, - isNot(throwsAssertionError), - ); - - expect( - () { - ListWheelScrollView( - overAndUnderCenterOpacity: 0, - itemExtent: 20.0, - children: [Container()], - ); - }, - isNot(throwsAssertionError), - ); - }); }); group('infinite scrolling', () { @@ -594,7 +537,7 @@ void main() { find.byKey(const Key('list_wheel_scroll_view')), matchesGoldenFile( 'list_wheel_scroll_view.center_child.magnified.png', - version: 1, + version: null, ), ); }, skip: isBrowser); @@ -651,7 +594,7 @@ void main() { find.byKey(const Key('list_wheel_scroll_view')), matchesGoldenFile( 'list_wheel_scroll_view.curved_wheel.left.png', - version: 1, + version: null, ), ); }, skip: isBrowser);