From eacb3d0dafd3a5356c5f6090a9302c702bbcda01 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 25 Jun 2026 00:53:23 +0000 Subject: [PATCH 1/3] Migrate sliding_segmented_control_test.dart to SemanticsHandle --- .../sliding_segmented_control_test.dart | 137 ++++++++---------- 1 file changed, 57 insertions(+), 80 deletions(-) rename packages/cupertino_ui/{temporarily_disabled_tests => test}/sliding_segmented_control_test.dart (95%) diff --git a/packages/cupertino_ui/temporarily_disabled_tests/sliding_segmented_control_test.dart b/packages/cupertino_ui/test/sliding_segmented_control_test.dart similarity index 95% rename from packages/cupertino_ui/temporarily_disabled_tests/sliding_segmented_control_test.dart rename to packages/cupertino_ui/test/sliding_segmented_control_test.dart index 1b0b5c3f938c..c134c0d949f0 100644 --- a/packages/cupertino_ui/temporarily_disabled_tests/sliding_segmented_control_test.dart +++ b/packages/cupertino_ui/test/sliding_segmented_control_test.dart @@ -2,9 +2,6 @@ // 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.', -) // reduced-test-set: // This file is run as part of a reduced test set in CI on Mac and Windows // machines. @@ -20,8 +17,6 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -import '../widgets/semantics_tester.dart'; - RenderBox getRenderSegmentedControl(WidgetTester tester) { return tester.allRenderObjects.firstWhere((RenderObject currentObject) { return currentObject.toStringShort().contains('_RenderSegmentedControl'); @@ -946,7 +941,8 @@ void main() { }); testWidgets('Segmented control semantics', (WidgetTester tester) async { - final semantics = SemanticsTester(tester); + final SemanticsHandle handle = tester.ensureSemantics(); + const children = {0: Text('Child 1'), 1: Text('Child 2')}; await tester.pumpWidget( @@ -962,42 +958,35 @@ void main() { ); expect( - semantics, - hasSemantics( - TestSemantics.root( - children: [ - TestSemantics.rootChild( - role: SemanticsRole.radioGroup, - children: [ - TestSemantics( - label: 'Child 1', - flags: [ - SemanticsFlag.isButton, - SemanticsFlag.isInMutuallyExclusiveGroup, - SemanticsFlag.hasSelectedState, - SemanticsFlag.isSelected, - SemanticsFlag.isFocusable, - ], - actions: [SemanticsAction.tap, SemanticsAction.focus], - ), - TestSemantics( - label: 'Child 2', - flags: [ - SemanticsFlag.isButton, - SemanticsFlag.isInMutuallyExclusiveGroup, - // Declares that it is selectable, but not currently selected. - SemanticsFlag.hasSelectedState, - SemanticsFlag.isFocusable, - ], - actions: [SemanticsAction.tap, SemanticsAction.focus], - ), - ], - ), - ], - ), - ignoreId: true, - ignoreRect: true, - ignoreTransform: true, + tester.getSemantics(find.byType(CupertinoSlidingSegmentedControl)).role, + SemanticsRole.radioGroup, + ); + + expect( + tester.getSemantics(find.text('Child 1')), + isSemantics( + label: 'Child 1', + isButton: true, + isInMutuallyExclusiveGroup: true, + hasSelectedState: true, + isSelected: true, + isFocusable: true, + hasTapAction: true, + hasFocusAction: true, + ), + ); + + expect( + tester.getSemantics(find.text('Child 2')), + isSemantics( + label: 'Child 2', + isButton: true, + isInMutuallyExclusiveGroup: true, + hasSelectedState: true, + isSelected: false, + isFocusable: true, + hasTapAction: true, + hasFocusAction: true, ), ); @@ -1005,47 +994,35 @@ void main() { await tester.pump(); expect( - semantics, - hasSemantics( - TestSemantics.root( - children: [ - TestSemantics.rootChild( - role: SemanticsRole.radioGroup, - children: [ - TestSemantics( - label: 'Child 1', - flags: [ - SemanticsFlag.isButton, - SemanticsFlag.isInMutuallyExclusiveGroup, - // Declares that it is selectable, but not currently selected. - SemanticsFlag.hasSelectedState, - SemanticsFlag.isFocusable, - ], - actions: [SemanticsAction.tap, SemanticsAction.focus], - ), - TestSemantics( - label: 'Child 2', - flags: [ - SemanticsFlag.isButton, - SemanticsFlag.isInMutuallyExclusiveGroup, - SemanticsFlag.hasSelectedState, - SemanticsFlag.isSelected, - SemanticsFlag.isFocusable, - SemanticsFlag.isFocused, - ], - actions: [SemanticsAction.tap, SemanticsAction.focus], - ), - ], - ), - ], - ), - ignoreId: true, - ignoreRect: true, - ignoreTransform: true, + tester.getSemantics(find.text('Child 1')), + isSemantics( + label: 'Child 1', + isButton: true, + isInMutuallyExclusiveGroup: true, + hasSelectedState: true, + isSelected: false, + isFocusable: true, + hasTapAction: true, + hasFocusAction: true, + ), + ); + + expect( + tester.getSemantics(find.text('Child 2')), + isSemantics( + label: 'Child 2', + isButton: true, + isInMutuallyExclusiveGroup: true, + hasSelectedState: true, + isSelected: true, + isFocusable: true, + isFocused: true, + hasTapAction: true, + hasFocusAction: true, ), ); - semantics.dispose(); + handle.dispose(); }); testWidgets('Non-centered taps work on smaller widgets', (WidgetTester tester) async { From cf962407e377e157d867f77531425b4ad13f65b0 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Thu, 25 Jun 2026 01:12:26 +0000 Subject: [PATCH 2/3] update --- .../cupertino_ui/test/sliding_segmented_control_test.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/cupertino_ui/test/sliding_segmented_control_test.dart b/packages/cupertino_ui/test/sliding_segmented_control_test.dart index c134c0d949f0..2b464e4fdcb3 100644 --- a/packages/cupertino_ui/test/sliding_segmented_control_test.dart +++ b/packages/cupertino_ui/test/sliding_segmented_control_test.dart @@ -993,6 +993,11 @@ void main() { await tester.tap(find.text('Child 2')); await tester.pump(); + expect( + tester.getSemantics(find.byType(CupertinoSlidingSegmentedControl)).role, + SemanticsRole.radioGroup, + ); + expect( tester.getSemantics(find.text('Child 1')), isSemantics( From 0a0d835e4502ec5da9e3387762bb2d9ea4d7a5d3 Mon Sep 17 00:00:00 2001 From: Renzo Olivares Date: Tue, 30 Jun 2026 22:50:11 +0000 Subject: [PATCH 3/3] remove ensureSemantics --- .../cupertino_ui/test/sliding_segmented_control_test.dart | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/cupertino_ui/test/sliding_segmented_control_test.dart b/packages/cupertino_ui/test/sliding_segmented_control_test.dart index 2b464e4fdcb3..90d6d21181f1 100644 --- a/packages/cupertino_ui/test/sliding_segmented_control_test.dart +++ b/packages/cupertino_ui/test/sliding_segmented_control_test.dart @@ -941,8 +941,6 @@ void main() { }); testWidgets('Segmented control semantics', (WidgetTester tester) async { - final SemanticsHandle handle = tester.ensureSemantics(); - const children = {0: Text('Child 1'), 1: Text('Child 2')}; await tester.pumpWidget( @@ -1026,8 +1024,6 @@ void main() { hasFocusAction: true, ), ); - - handle.dispose(); }); testWidgets('Non-centered taps work on smaller widgets', (WidgetTester tester) async {