update CupertinoPicker.selectionOverlay to nullable (#79620)

This commit is contained in:
xubaolin 2021-04-06 12:39:01 +08:00 committed by GitHub
parent 2c454a7536
commit ccf83d1de9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -198,7 +198,7 @@ class CupertinoPicker extends StatefulWidget {
/// If unspecified, it defaults to a [CupertinoPickerDefaultSelectionOverlay]
/// which is a gray rounded rectangle overlay in iOS 14 style.
/// This property can be set to null to remove the overlay.
final Widget selectionOverlay;
final Widget? selectionOverlay;
@override
State<StatefulWidget> createState() => _CupertinoPickerState();
@ -301,7 +301,8 @@ class _CupertinoPickerState extends State<CupertinoPicker> {
),
),
),
_buildSelectionOverlay(widget.selectionOverlay),
if (widget.selectionOverlay != null)
_buildSelectionOverlay(widget.selectionOverlay!),
],
),
);

View File

@ -172,6 +172,29 @@ void main() {
expect(find.byType(CupertinoPicker), paints..rrect(color: const Color(0x12345678)));
});
testWidgets('CupertinoPicker.selectionOverlay is nullable', (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(
itemExtent: 15.0,
children: const <Widget>[Text('1'), Text('1')],
onSelectedItemChanged: (int i) {},
selectionOverlay: null,
),
),
),
),
);
expect(find.byType(CupertinoPicker), isNot(paints..rrect()));
});
group('scroll', () {
testWidgets(
'scrolling calls onSelectedItemChanged and triggers haptic feedback',