Add framework-side hitTestBehavior support for Semantics widget and apply to ModalRoute
diff --git a/packages/flutter/lib/src/rendering/custom_paint.dart b/packages/flutter/lib/src/rendering/custom_paint.dart index ffd1a32..4bc5ae5 100644 --- a/packages/flutter/lib/src/rendering/custom_paint.dart +++ b/packages/flutter/lib/src/rendering/custom_paint.dart
@@ -1039,6 +1039,9 @@ if (config.validationResult != properties.validationResult) { config.validationResult = properties.validationResult; } + if (properties.hitTestBehavior != null) { + config.hitTestBehavior = properties.hitTestBehavior!; + } if (properties.inputType != null) { config.inputType = properties.inputType!; }
diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart index 12a9c61..089a259 100644 --- a/packages/flutter/lib/src/rendering/object.dart +++ b/packages/flutter/lib/src/rendering/object.dart
@@ -4935,6 +4935,10 @@ config.validationResult = _properties.validationResult; } + if (_properties.hitTestBehavior != null) { + config.hitTestBehavior = _properties.hitTestBehavior!; + } + if (_properties.inputType != null) { config.inputType = _properties.inputType!; }
diff --git a/packages/flutter/lib/src/semantics/semantics.dart b/packages/flutter/lib/src/semantics/semantics.dart index d3c46b8..5ff42a7 100644 --- a/packages/flutter/lib/src/semantics/semantics.dart +++ b/packages/flutter/lib/src/semantics/semantics.dart
@@ -12,6 +12,7 @@ import 'dart:core'; import 'dart:math' as math; import 'dart:ui' + as ui show CheckedState, Locale, @@ -20,6 +21,7 @@ SemanticsAction, SemanticsFlag, SemanticsFlags, + SemanticsHitTestBehavior, SemanticsInputType, SemanticsRole, SemanticsUpdate, @@ -978,6 +980,7 @@ required this.role, required this.controlsNodes, required this.validationResult, + required this.hitTestBehavior, required this.inputType, required this.locale, this.tags, @@ -1240,6 +1243,9 @@ /// {@macro flutter.semantics.SemanticsProperties.validationResult} final SemanticsValidationResult validationResult; + /// {@macro flutter.semantics.SemanticsProperties.hitTestBehavior} + final ui.SemanticsHitTestBehavior hitTestBehavior; + /// {@macro flutter.semantics.SemanticsNode.inputType} final SemanticsInputType inputType; @@ -1542,6 +1548,7 @@ this.controlsNodes, this.inputType, this.validationResult = SemanticsValidationResult.none, + this.hitTestBehavior, this.onTap, this.onLongPress, this.onScrollLeft, @@ -2434,6 +2441,13 @@ /// {@endtemplate} final SemanticsValidationResult validationResult; + /// {@template flutter.semantics.SemanticsProperties.hitTestBehavior} + /// Describes how the semantic node should behave during hit testing. + /// + /// See [ui.SemanticsHitTestBehavior] for more details. + /// {@endtemplate} + final ui.SemanticsHitTestBehavior? hitTestBehavior; + /// {@template flutter.semantics.SemanticsProperties.inputType} /// The input type for of a editable widget. /// @@ -3063,7 +3077,8 @@ _headingLevel != config._headingLevel || _linkUrl != config._linkUrl || _role != config.role || - _validationResult != config.validationResult; + _validationResult != config.validationResult || + _hitTestBehavior != config.hitTestBehavior; } // TAGS, LABELS, ACTIONS @@ -3346,6 +3361,10 @@ SemanticsValidationResult get validationResult => _validationResult; SemanticsValidationResult _validationResult = _kEmptyConfig.validationResult; + /// {@macro flutter.semantics.SemanticsProperties.hitTestBehavior} + ui.SemanticsHitTestBehavior get hitTestBehavior => _hitTestBehavior; + ui.SemanticsHitTestBehavior _hitTestBehavior = ui.SemanticsHitTestBehavior.defer; + /// {@template flutter.semantics.SemanticsNode.inputType} /// The input type for of a editable node. /// @@ -3424,6 +3443,7 @@ _role = config._role; _controlsNodes = config._controlsNodes; _validationResult = config._validationResult; + _hitTestBehavior = config._hitTestBehavior; _inputType = config._inputType; _locale = config.locale; @@ -3476,6 +3496,7 @@ SemanticsRole role = _role; Set<String>? controlsNodes = _controlsNodes; SemanticsValidationResult validationResult = _validationResult; + ui.SemanticsHitTestBehavior hitTestBehavior = _hitTestBehavior; SemanticsInputType inputType = _inputType; final Locale? locale = _locale; final Set<int> customSemanticsActionIds = <int>{}; @@ -3627,6 +3648,7 @@ role: role, controlsNodes: controlsNodes, validationResult: validationResult, + hitTestBehavior: hitTestBehavior, inputType: inputType, locale: locale, ); @@ -3714,6 +3736,7 @@ role: data.role, controlsNodes: data.controlsNodes?.toList(), validationResult: data.validationResult, + hitTestBehavior: data.hitTestBehavior, inputType: data.inputType, locale: data.locale, ); @@ -5947,6 +5970,14 @@ _hasBeenAnnotated = true; } + /// {@macro flutter.semantics.SemanticsProperties.hitTestBehavior} + ui.SemanticsHitTestBehavior get hitTestBehavior => _hitTestBehavior; + ui.SemanticsHitTestBehavior _hitTestBehavior = ui.SemanticsHitTestBehavior.defer; + set hitTestBehavior(ui.SemanticsHitTestBehavior value) { + _hitTestBehavior = value; + _hasBeenAnnotated = true; + } + /// {@macro flutter.semantics.SemanticsProperties.inputType} SemanticsInputType get inputType => _inputType; SemanticsInputType _inputType = SemanticsInputType.none;
diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index f583d04..b13f74c 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart
@@ -9,7 +9,9 @@ library; import 'dart:math' as math; -import 'dart:ui' as ui show Image, ImageFilter, SemanticsInputType, TextHeightBehavior; +import 'dart:ui' + as ui + show Image, ImageFilter, SemanticsHitTestBehavior, SemanticsInputType, TextHeightBehavior; import 'package:flutter/animation.dart'; import 'package:flutter/foundation.dart'; @@ -4045,6 +4047,7 @@ required SemanticsRole? role, required Set<String>? controlsNodes, required SemanticsValidationResult validationResult, + required ui.SemanticsHitTestBehavior? hitTestBehavior, required ui.SemanticsInputType? inputType, required Locale? localeForSubtree, }) : this.fromProperties( @@ -4127,6 +4130,7 @@ role: role, controlsNodes: controlsNodes, validationResult: validationResult, + hitTestBehavior: hitTestBehavior, inputType: inputType, ), ); @@ -7948,6 +7952,7 @@ super.role, super.controlsNodes, super.validationResult = SemanticsValidationResult.none, + super.hitTestBehavior, super.inputType, super.localeForSubtree, });
diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart index 48927ea..a64b610 100644 --- a/packages/flutter/lib/src/widgets/routes.dart +++ b/packages/flutter/lib/src/widgets/routes.dart
@@ -2313,6 +2313,7 @@ // To be sorted before the _modalBarrier. return _modalScopeCache ??= Semantics( sortKey: const OrdinalSortKey(0.0), + hitTestBehavior: ui.SemanticsHitTestBehavior.opaque, child: _ModalScope<T>( key: _scopeKey, route: this,