模态路由中叠加层条目的语义顺序
摘要
#我们更改了模态路由中叠加层条目的语义遍历顺序。辅助功能语音反馈或 VoiceOver 现在首先关注模态路由的范围,而不是其模态屏障。
上下文
#模态路由有两个叠加层条目,范围和模态屏障。范围是模态路由的实际内容,模态屏障是路由的背景(如果其范围没有覆盖整个屏幕)。如果模态路由对于barrierDismissible
返回 true,则模态屏障变得可访问焦点,因为用户可以通过点击模态屏障来弹出模态路由。此更改专门使辅助功能在模态屏障之前首先聚焦范围。
更改说明
#我们在模态路由(Modal Route)的两个覆盖条目(Overlay Entry)上方添加了额外的语义节点(Semantics Node)。这些语义节点表示这两个覆盖条目的语义遍历顺序。这也改变了语义树的结构。
迁移指南
#如果您的测试由于更新后的语义树更改而开始失败,您可以通过在模态路由覆盖条目上方预期一个新的节点来迁移您的代码。
迁移前的代码
dart
import 'dart:ui';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
void main() {
testWidgets('example test', (WidgetTester tester) async {
final SemanticsHandle handle =
tester.binding.pipelineOwner.ensureSemantics();
// Build our app and trigger a frame.
await tester.pumpWidget(MaterialApp(home: Scaffold(body: Text('test'))));
final SemanticsNode root =
tester.binding.pipelineOwner.semanticsOwner.rootSemanticsNode;
final SemanticsNode firstNode = getChild(root);
expect(firstNode.rect, Rect.fromLTRB(0.0, 0.0, 800.0, 600.0));
// Fixes the test by expecting an additional node above the scope route.
final SemanticsNode secondNode = getChild(firstNode);
expect(secondNode.rect, Rect.fromLTRB(0.0, 0.0, 800.0, 600.0));
final SemanticsNode thirdNode = getChild(secondNode);
expect(thirdNode.rect, Rect.fromLTRB(0.0, 0.0, 800.0, 600.0));
expect(thirdNode.hasFlag(SemanticsFlag.scopesRoute), true);
final SemanticsNode forthNode = getChild(thirdNode);
expect(forthNode.rect, Rect.fromLTRB(0.0, 0.0, 56.0, 14.0));
expect(forthNode.label, 'test');
handle.dispose();
});
}
SemanticsNode getChild(SemanticsNode node) {
SemanticsNode child;
bool visiter(SemanticsNode target) {
child = target;
return false;
}
node.visitChildren(visiter);
return child;
}
迁移后的代码
dart
import 'dart:ui';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
void main() {
testWidgets('example test', (WidgetTester tester) async {
final SemanticsHandle handle =
tester.binding.pipelineOwner.ensureSemantics();
// Build our app and trigger a frame.
await tester.pumpWidget(MaterialApp(home: Scaffold(body: Text('test'))));
final SemanticsNode root =
tester.binding.pipelineOwner.semanticsOwner.rootSemanticsNode;
final SemanticsNode firstNode = getChild(root);
expect(firstNode.rect, Rect.fromLTRB(0.0, 0.0, 800.0, 600.0));
// Fixes the test by expecting an additional node above the scope route.
final SemanticsNode secondNode = getChild(firstNode);
expect(secondNode.rect, Rect.fromLTRB(0.0, 0.0, 800.0, 600.0));
final SemanticsNode thirdNode = getChild(secondNode);
expect(thirdNode.rect, Rect.fromLTRB(0.0, 0.0, 800.0, 600.0));
expect(thirdNode.hasFlag(SemanticsFlag.scopesRoute), true);
final SemanticsNode forthNode = getChild(thirdNode);
expect(forthNode.rect, Rect.fromLTRB(0.0, 0.0, 56.0, 14.0));
expect(forthNode.label, 'test');
handle.dispose();
});
}
SemanticsNode getChild(SemanticsNode node) {
SemanticsNode child;
bool visiter(SemanticsNode target) {
child = target;
return false;
}
node.visitChildren(visiter);
return child;
}
时间线
#包含于版本:1.19.0
稳定版发布:1.20
参考文献
#API 文档
相关问题
相关 PR
除非另有说明,否则本网站上的文档反映了 Flutter 的最新稳定版本。页面最后更新于 2024-04-04。 查看源代码 或 报告问题.