diff --git a/packages/flutter/lib/src/cupertino/picker.dart b/packages/flutter/lib/src/cupertino/picker.dart index 4176853df9..99fa470402 100644 --- a/packages/flutter/lib/src/cupertino/picker.dart +++ b/packages/flutter/lib/src/cupertino/picker.dart @@ -215,7 +215,7 @@ class _CupertinoPickerState extends State { if (widget.backgroundColor != null && widget.backgroundColor.alpha < 255) return Container(); - final Color widgetBackgroundColor = widget.backgroundColor; + final Color widgetBackgroundColor = widget.backgroundColor ?? const Color(0xFFFFFFFF); return Positioned.fill( child: IgnorePointer( child: Container( diff --git a/packages/flutter/test/cupertino/picker_test.dart b/packages/flutter/test/cupertino/picker_test.dart index 367faca357..cf410d4f4a 100644 --- a/packages/flutter/test/cupertino/picker_test.dart +++ b/packages/flutter/test/cupertino/picker_test.dart @@ -132,6 +132,49 @@ void main() { expect(boxDecoration.gradient, isNull); expect(boxDecoration.color, isNotNull); }); + + 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', () {