Adds dialog and alertdialog role (#162692)

<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

fixes https://github.com/flutter/flutter/issues/162124
fixes https://github.com/flutter/flutter/issues/157207
fixes https://github.com/flutter/flutter/issues/157204

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
chunhtai
2025-02-11 11:51:05 -08:00
committed by GitHub
parent 04cbda2b1a
commit 21471aa236
11 changed files with 211 additions and 38 deletions

View File

@@ -9,7 +9,7 @@
library;
import 'dart:math' as math;
import 'dart:ui' show ImageFilter, lerpDouble;
import 'dart:ui' show ImageFilter, SemanticsRole, lerpDouble;
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
@@ -463,6 +463,7 @@ class _CupertinoAlertDialogState extends State<CupertinoAlertDialog> {
child: CupertinoPopupSurface(
isSurfacePainted: false,
child: Semantics(
role: SemanticsRole.alertDialog,
namesRoute: true,
scopesRoute: true,
explicitChildNodes: true,
@@ -1332,6 +1333,7 @@ class _CupertinoActionSheetState extends State<CupertinoActionSheet> {
namesRoute: true,
scopesRoute: true,
explicitChildNodes: true,
role: SemanticsRole.dialog,
label: 'Alert',
child: CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,

View File

@@ -10,7 +10,7 @@
/// @docImport 'text_button.dart';
library;
import 'dart:ui' show clampDouble, lerpDouble;
import 'dart:ui' show SemanticsRole, clampDouble, lerpDouble;
import 'package:flutter/cupertino.dart';
@@ -67,6 +67,7 @@ class Dialog extends StatelessWidget {
this.shape,
this.alignment,
this.child,
this.semanticsRole = SemanticsRole.dialog,
}) : assert(elevation == null || elevation >= 0.0),
_fullscreen = false;
@@ -79,6 +80,7 @@ class Dialog extends StatelessWidget {
this.insetAnimationDuration = Duration.zero,
this.insetAnimationCurve = Curves.decelerate,
this.child,
this.semanticsRole = SemanticsRole.dialog,
}) : elevation = 0,
shadowColor = null,
surfaceTintColor = null,
@@ -229,6 +231,11 @@ class Dialog extends StatelessWidget {
/// This value is used to determine if this is a fullscreen dialog.
final bool _fullscreen;
/// The role this dialog represent in assist technologies.
///
/// Defaults to [SemanticsRole.dialog].
final SemanticsRole semanticsRole;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
@@ -268,17 +275,20 @@ class Dialog extends StatelessWidget {
);
}
return AnimatedPadding(
padding: effectivePadding,
duration: insetAnimationDuration,
curve: insetAnimationCurve,
child: MediaQuery.removeViewInsets(
removeLeft: true,
removeTop: true,
removeRight: true,
removeBottom: true,
context: context,
child: dialogChild,
return Semantics(
role: semanticsRole,
child: AnimatedPadding(
padding: effectivePadding,
duration: insetAnimationDuration,
curve: insetAnimationCurve,
child: MediaQuery.removeViewInsets(
removeLeft: true,
removeTop: true,
removeRight: true,
removeBottom: true,
context: context,
child: dialogChild,
),
),
);
}
@@ -918,6 +928,7 @@ class AlertDialog extends StatelessWidget {
clipBehavior: clipBehavior,
shape: shape,
alignment: alignment,
semanticsRole: SemanticsRole.alertDialog,
child: dialogChild,
);
}

View File

@@ -104,6 +104,8 @@ final int _kUnblockedUserActions =
/// A static class to conduct semantics role checks.
sealed class _DebugSemanticsRoleChecks {
static FlutterError? _checkSemanticsData(SemanticsNode node) => switch (node.role) {
SemanticsRole.alertDialog => _noCheckRequired,
SemanticsRole.dialog => _noCheckRequired,
SemanticsRole.none => _noCheckRequired,
SemanticsRole.tab => _semanticsTab,
SemanticsRole.tabBar => _semanticsTabBar,

View File

@@ -7,9 +7,10 @@
@Tags(<String>['reduced-test-set'])
library;
import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
@@ -1760,6 +1761,7 @@ void main() {
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute, SemanticsFlag.namesRoute],
label: 'Alert',
role: SemanticsRole.dialog,
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.hasImplicitScrolling],

View File

@@ -711,6 +711,7 @@ void main() {
SemanticsFlag.scopesRoute,
SemanticsFlag.namesRoute,
],
role: SemanticsRole.alertDialog,
label: 'Alert',
children: <TestSemantics>[
TestSemantics(

View File

@@ -1616,6 +1616,7 @@ void main() {
children: <TestSemantics>[
TestSemantics(
id: 4,
role: SemanticsRole.alertDialog,
children: <TestSemantics>[
TestSemantics(id: 5, label: 'title', textDirection: TextDirection.ltr),
// The content semantics does not merge into the semantics
@@ -1803,6 +1804,7 @@ void main() {
children: <TestSemantics>[
TestSemantics(
id: 4,
role: SemanticsRole.dialog,
children: <TestSemantics>[
// Title semantics does not merge into the semantics
// node 4.