diff --git a/packages/flutter/lib/src/semantics/semantics.dart b/packages/flutter/lib/src/semantics/semantics.dart index 9a971c56db..4f6254f309 100644 --- a/packages/flutter/lib/src/semantics/semantics.dart +++ b/packages/flutter/lib/src/semantics/semantics.dart @@ -101,31 +101,14 @@ final int _kUnblockedUserActions = SemanticsAction.didGainAccessibilityFocus.index | SemanticsAction.didLoseAccessibilityFocus.index; -/// Function signature for checks in [DebugSemanticsRoleChecks.kChecks]. -/// -/// The check is run against any `node` that is sent to the platform. -/// -/// To access the flags and properties, one should call the -/// [SemanticsNode.getSemanticsData]. -@visibleForTesting -typedef DebugSemanticsRoleCheck = FlutterError? Function(SemanticsNode node); - /// A static class to conduct semantics role checks. -/// -/// When adding a new [SemanticsRole], one must also add a corresponding check -/// to [kChecks]. -@visibleForTesting -sealed class DebugSemanticsRoleChecks { - /// A map to map each [SemanticsRole] to its check. - static const Map kChecks = - { - SemanticsRole.none: _noCheckRequired, - SemanticsRole.tab: _semanticsTab, - SemanticsRole.tabBar: _semanticsTabBar, - SemanticsRole.tabPanel: _noCheckRequired, - }; - - static FlutterError? _checkSemanticsData(SemanticsNode node) => kChecks[node.role]!(node); +sealed class _DebugSemanticsRoleChecks { + static FlutterError? _checkSemanticsData(SemanticsNode node) => switch (node.role) { + SemanticsRole.none => _noCheckRequired, + SemanticsRole.tab => _semanticsTab, + SemanticsRole.tabBar => _semanticsTabBar, + SemanticsRole.tabPanel => _noCheckRequired, + }(node); static FlutterError? _noCheckRequired(SemanticsNode node) => null; @@ -3060,7 +3043,7 @@ class SemanticsNode with DiagnosticableTreeMixin { assert(_dirty); final SemanticsData data = getSemanticsData(); assert(() { - final FlutterError? error = DebugSemanticsRoleChecks._checkSemanticsData(this); + final FlutterError? error = _DebugSemanticsRoleChecks._checkSemanticsData(this); if (error != null) { throw error; } diff --git a/packages/flutter/test/widgets/semantics_role_checks_test.dart b/packages/flutter/test/widgets/semantics_role_checks_test.dart index 3efa502010..4775570d9e 100644 --- a/packages/flutter/test/widgets/semantics_role_checks_test.dart +++ b/packages/flutter/test/widgets/semantics_role_checks_test.dart @@ -4,15 +4,10 @@ import 'dart:ui'; -import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { - test('All semantics roles has checks', () { - expect(SemanticsRole.values.toSet(), DebugSemanticsRoleChecks.kChecks.keys.toSet()); - }); - group('tab', () { testWidgets('failure case, empty', (WidgetTester tester) async { await tester.pumpWidget(