From 3b60bd72845ff0fd025607a181629574b9e753ec Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 25 Jun 2026 00:54:08 +0000 Subject: [PATCH 1/2] Migrate picker_test.dart to SemanticsHandle --- .../picker_test.dart | 140 ++++++++++-------- 1 file changed, 76 insertions(+), 64 deletions(-) rename packages/cupertino_ui/{temporarily_disabled_tests => test}/picker_test.dart (91%) diff --git a/packages/cupertino_ui/temporarily_disabled_tests/picker_test.dart b/packages/cupertino_ui/test/picker_test.dart similarity index 91% rename from packages/cupertino_ui/temporarily_disabled_tests/picker_test.dart rename to packages/cupertino_ui/test/picker_test.dart index 9efd956e277c..554725d8add2 100644 --- a/packages/cupertino_ui/temporarily_disabled_tests/picker_test.dart +++ b/packages/cupertino_ui/test/picker_test.dart @@ -2,17 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -@Skip( - 'This file is skipped due to a cross-import that needs to be fixed. Tracked in https://github.com/flutter/flutter/issues/177028.', -) import 'package:cupertino_ui/cupertino_ui.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import '../widgets/semantics_tester.dart'; - /// A [CustomPainter] that calls a callback when it paints. class TestCallbackPainter extends CustomPainter { /// Creates a [TestCallbackPainter] that calls [onPaint] when it paints. @@ -73,7 +68,7 @@ void main() { }); testWidgets('Picker semantics', (WidgetTester tester) async { - final semantics = SemanticsTester(tester); + final SemanticsHandle handle = tester.ensureSemantics(); await tester.pumpWidget( CupertinoApp( @@ -90,11 +85,16 @@ void main() { ), ); expect( - semantics, - includesNodeWith( + tester.getSemantics( + find.byWidgetPredicate( + (Widget widget) => widget.runtimeType.toString() == '_CupertinoPickerSemantics', + ), + ), + isSemantics( value: '0', increasedValue: '1', - actions: [SemanticsAction.increase], + hasIncreaseAction: true, + hasDecreaseAction: false, ), ); @@ -105,15 +105,21 @@ void main() { hourListController.jumpToItem(11); await tester.pumpAndSettle(); expect( - semantics, - includesNodeWith( + tester.getSemantics( + find.byWidgetPredicate( + (Widget widget) => widget.runtimeType.toString() == '_CupertinoPickerSemantics', + ), + ), + isSemantics( value: '11', increasedValue: '12', decreasedValue: '10', - actions: [SemanticsAction.increase, SemanticsAction.decrease], + hasIncreaseAction: true, + hasDecreaseAction: true, ), ); - semantics.dispose(); + + handle.dispose(); }); testWidgets('Picker semantics excludes current item with empty label', ( @@ -121,67 +127,73 @@ void main() { ) async { // When the current item has an empty label (e.g., wrapped with ExcludeSemantics), // the picker should not set any value, increasedValue, decreasedValue, or actions. - final semantics = SemanticsTester(tester); + final SemanticsHandle handle = tester.ensureSemantics(); final controller = FixedExtentScrollController(initialItem: 1); addTearDown(controller.dispose); - await tester.pumpWidget( - CupertinoApp( - home: SizedBox.square( - dimension: 300.0, - child: CupertinoPicker( - scrollController: controller, - itemExtent: 50.0, - onSelectedItemChanged: (_) {}, - children: const [ - Text('0'), - // Item at index 1 is excluded from semantics (simulating a disabled item). - ExcludeSemantics(child: Text('1')), - Text('2'), - ], + try { + await tester.pumpWidget( + CupertinoApp( + home: SizedBox.square( + dimension: 300.0, + child: CupertinoPicker( + scrollController: controller, + itemExtent: 50.0, + onSelectedItemChanged: (_) {}, + children: const [ + Text('0'), + // Item at index 1 is excluded from semantics (simulating a disabled item). + ExcludeSemantics(child: Text('1')), + Text('2'), + ], + ), ), ), - ), - ); - - // When the current item (index 1) has an empty label due to ExcludeSemantics, - // the picker should not have any value or actions set. - expect(semantics, isNot(includesNodeWith(value: '1'))); - // Also verify that no increase/decrease actions are set for this item. - expect( - semantics, - isNot(includesNodeWith(actions: [SemanticsAction.increase])), - ); - expect( - semantics, - isNot(includesNodeWith(actions: [SemanticsAction.decrease])), - ); + ); - // Scroll to item 0 which has a valid label. - controller.jumpToItem(0); - await tester.pumpAndSettle(); + // When the current item (index 1) has an empty label due to ExcludeSemantics, + // the picker should not have any value or actions set. + expect( + tester.getSemantics( + find.byWidgetPredicate( + (Widget widget) => widget.runtimeType.toString() == '_CupertinoPickerSemantics', + ), + ), + isSemantics(value: '', hasIncreaseAction: false, hasDecreaseAction: false), + ); - // Now the picker should have value '0' but no increase action - // because the next item (1) has an empty label. - expect(semantics, includesNodeWith(value: '0')); - expect( - semantics, - isNot(includesNodeWith(value: '0', actions: [SemanticsAction.increase])), - ); + // Scroll to item 0 which has a valid label. + controller.jumpToItem(0); + await tester.pumpAndSettle(); - // Scroll to item 2 which has a valid label. - controller.jumpToItem(2); - await tester.pumpAndSettle(); + // Now the picker should have value '0' but no increase action + // because the next item (1) has an empty label. + expect( + tester.getSemantics( + find.byWidgetPredicate( + (Widget widget) => widget.runtimeType.toString() == '_CupertinoPickerSemantics', + ), + ), + isSemantics(value: '0', hasIncreaseAction: false, hasDecreaseAction: false), + ); - // Now the picker should have value '2' but no decrease action - // because the previous item (1) has an empty label. - expect(semantics, includesNodeWith(value: '2')); - expect( - semantics, - isNot(includesNodeWith(value: '2', actions: [SemanticsAction.decrease])), - ); + // Scroll to item 2 which has a valid label. + controller.jumpToItem(2); + await tester.pumpAndSettle(); - semantics.dispose(); + // Now the picker should have value '2' but no decrease action + // because the previous item (1) has an empty label. + expect( + tester.getSemantics( + find.byWidgetPredicate( + (Widget widget) => widget.runtimeType.toString() == '_CupertinoPickerSemantics', + ), + ), + isSemantics(value: '2', hasDecreaseAction: false, hasIncreaseAction: false), + ); + } finally { + handle.dispose(); + } }); group('layout', () { From bebbeb00c45019a6c90e07d46b14af2783574f89 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 25 Jun 2026 21:21:14 +0000 Subject: [PATCH 2/2] remove try/catch --- packages/cupertino_ui/test/picker_test.dart | 103 ++++++++++---------- 1 file changed, 50 insertions(+), 53 deletions(-) diff --git a/packages/cupertino_ui/test/picker_test.dart b/packages/cupertino_ui/test/picker_test.dart index 554725d8add2..a739f38b9d12 100644 --- a/packages/cupertino_ui/test/picker_test.dart +++ b/packages/cupertino_ui/test/picker_test.dart @@ -131,69 +131,66 @@ void main() { final controller = FixedExtentScrollController(initialItem: 1); addTearDown(controller.dispose); - try { - await tester.pumpWidget( - CupertinoApp( - home: SizedBox.square( - dimension: 300.0, - child: CupertinoPicker( - scrollController: controller, - itemExtent: 50.0, - onSelectedItemChanged: (_) {}, - children: const [ - Text('0'), - // Item at index 1 is excluded from semantics (simulating a disabled item). - ExcludeSemantics(child: Text('1')), - Text('2'), - ], - ), + await tester.pumpWidget( + CupertinoApp( + home: SizedBox.square( + dimension: 300.0, + child: CupertinoPicker( + scrollController: controller, + itemExtent: 50.0, + onSelectedItemChanged: (_) {}, + children: const [ + Text('0'), + // Item at index 1 is excluded from semantics (simulating a disabled item). + ExcludeSemantics(child: Text('1')), + Text('2'), + ], ), ), - ); + ), + ); - // When the current item (index 1) has an empty label due to ExcludeSemantics, - // the picker should not have any value or actions set. - expect( - tester.getSemantics( - find.byWidgetPredicate( - (Widget widget) => widget.runtimeType.toString() == '_CupertinoPickerSemantics', - ), + // When the current item (index 1) has an empty label due to ExcludeSemantics, + // the picker should not have any value or actions set. + expect( + tester.getSemantics( + find.byWidgetPredicate( + (Widget widget) => widget.runtimeType.toString() == '_CupertinoPickerSemantics', ), - isSemantics(value: '', hasIncreaseAction: false, hasDecreaseAction: false), - ); + ), + isSemantics(value: '', hasIncreaseAction: false, hasDecreaseAction: false), + ); - // Scroll to item 0 which has a valid label. - controller.jumpToItem(0); - await tester.pumpAndSettle(); + // Scroll to item 0 which has a valid label. + controller.jumpToItem(0); + await tester.pumpAndSettle(); - // Now the picker should have value '0' but no increase action - // because the next item (1) has an empty label. - expect( - tester.getSemantics( - find.byWidgetPredicate( - (Widget widget) => widget.runtimeType.toString() == '_CupertinoPickerSemantics', - ), + // Now the picker should have value '0' but no increase action + // because the next item (1) has an empty label. + expect( + tester.getSemantics( + find.byWidgetPredicate( + (Widget widget) => widget.runtimeType.toString() == '_CupertinoPickerSemantics', ), - isSemantics(value: '0', hasIncreaseAction: false, hasDecreaseAction: false), - ); + ), + isSemantics(value: '0', hasIncreaseAction: false, hasDecreaseAction: false), + ); - // Scroll to item 2 which has a valid label. - controller.jumpToItem(2); - await tester.pumpAndSettle(); + // Scroll to item 2 which has a valid label. + controller.jumpToItem(2); + await tester.pumpAndSettle(); - // Now the picker should have value '2' but no decrease action - // because the previous item (1) has an empty label. - expect( - tester.getSemantics( - find.byWidgetPredicate( - (Widget widget) => widget.runtimeType.toString() == '_CupertinoPickerSemantics', - ), + // Now the picker should have value '2' but no decrease action + // because the previous item (1) has an empty label. + expect( + tester.getSemantics( + find.byWidgetPredicate( + (Widget widget) => widget.runtimeType.toString() == '_CupertinoPickerSemantics', ), - isSemantics(value: '2', hasDecreaseAction: false, hasIncreaseAction: false), - ); - } finally { - handle.dispose(); - } + ), + isSemantics(value: '2', hasDecreaseAction: false, hasIncreaseAction: false), + ); + handle.dispose(); }); group('layout', () {