Content-Length: 464200 | pFad | http://github.com/flutter/flutter/commit/7197a8fa9ce68c6d08188b25a8a655e4aacb0030

3A Merge branch 'master' into fix/lang_a11y_on_Text · flutter/flutter@7197a8f · GitHub
Skip to content

Commit 7197a8f

Browse files
Merge branch 'master' into fix/lang_a11y_on_Text
2 parents b735c2c + 7015afc commit 7197a8f

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

packages/flutter/lib/src/material/popup_menu.dart

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,7 @@ class PopupMenuItemState<T, W extends PopupMenuItem<T>> extends State<W> {
450450
}
451451

452452
return MergeSemantics(
453-
child: Semantics(
454-
role: SemanticsRole.menuItem,
455-
enabled: widget.enabled,
456-
button: true,
453+
child: buildSemantics(
457454
child: InkWell(
458455
onTap: widget.enabled ? handleTap : null,
459456
canRequestFocus: widget.enabled,
@@ -467,6 +464,25 @@ class PopupMenuItemState<T, W extends PopupMenuItem<T>> extends State<W> {
467464
),
468465
);
469466
}
467+
468+
//github.com/ Builds the semantic wrapper for the popup menu item.
469+
//github.com/
470+
//github.com/ This method creates the [Semantics] widget that provides accessibility
471+
//github.com/ information for the menu item. By default, it sets the semantic role to
472+
//github.com/ [SemanticsRole.menuItem] and includes the enabled state and button flag.
473+
//github.com/
474+
//github.com/ Subclasses can override this method to customize the semantic properties.
475+
//github.com/ For example, [CheckedPopupMenuItem] overrides this to use
476+
//github.com/ [SemanticsRole.menuItemCheckbox] and include checked state information.
477+
@protected
478+
Widget buildSemantics({required Widget child}) {
479+
return Semantics(
480+
role: SemanticsRole.menuItem,
481+
enabled: widget.enabled,
482+
button: true,
483+
child: child,
484+
);
485+
}
470486
}
471487

472488
//github.com/ An item with a checkmark in a Material Design popup menu.
@@ -607,6 +623,17 @@ class _CheckedPopupMenuItemState<T> extends PopupMenuItemState<T, CheckedPopupMe
607623
super.handleTap();
608624
}
609625

626+
@override
627+
Widget buildSemantics({required Widget child}) {
628+
return Semantics(
629+
role: SemanticsRole.menuItemCheckbox,
630+
enabled: widget.enabled,
631+
checked: widget.checked,
632+
button: true,
633+
child: child,
634+
);
635+
}
636+
610637
@override
611638
Widget buildChild() {
612639
final ThemeData theme = Theme.of(context);

packages/flutter/test/material/popup_menu_test.dart

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,59 @@ void main() {
16041604
semantics.dispose();
16051605
});
16061606

1607+
testWidgets('CheckedPopupMenuItem has correct semantics', (WidgetTester tester) async {
1608+
final SemanticsTester semantics = SemanticsTester(tester);
1609+
await tester.pumpWidget(
1610+
MaterialApp(
1611+
home: Material(
1612+
child: PopupMenuButton<int>(
1613+
itemBuilder: (BuildContext context) {
1614+
return <PopupMenuEntry<int>>[
1615+
const CheckedPopupMenuItem<int>(
1616+
value: 1,
1617+
checked: true,
1618+
child: Text('Checked Item'),
1619+
),
1620+
const CheckedPopupMenuItem<int>(value: 2, child: Text('Unchecked Item')),
1621+
];
1622+
},
1623+
child: const SizedBox(height: 100.0, width: 100.0, child: Text('XXX')),
1624+
),
1625+
),
1626+
),
1627+
);
1628+
await tester.tap(find.text('XXX'));
1629+
await tester.pumpAndSettle();
1630+
1631+
// Verify that CheckedPopupMenuItem uses SemanticsRole.menuItemCheckbox
1632+
final Iterable<SemanticsNode> allNodes = semantics.nodesWith();
1633+
final List<SemanticsNode> menuItemNodes = allNodes
1634+
.where(
1635+
(SemanticsNode node) => node.getSemanticsData().role == SemanticsRole.menuItemCheckbox,
1636+
)
1637+
.toList();
1638+
expect(menuItemNodes, hasLength(2));
1639+
1640+
// Verify that the checked item has the correct properties
1641+
final SemanticsNode checkedNode = menuItemNodes.firstWhere(
1642+
(SemanticsNode node) => node.getSemanticsData().hasFlag(SemanticsFlag.isChecked),
1643+
);
1644+
expect(checkedNode.getSemanticsData().role, SemanticsRole.menuItemCheckbox);
1645+
expect(checkedNode.getSemanticsData().hasFlag(SemanticsFlag.isButton), isTrue);
1646+
expect(checkedNode.getSemanticsData().hasFlag(SemanticsFlag.hasCheckedState), isTrue);
1647+
1648+
// Verify that the unchecked item has the correct properties
1649+
final SemanticsNode uncheckedNode = menuItemNodes.firstWhere(
1650+
(SemanticsNode node) => !node.getSemanticsData().hasFlag(SemanticsFlag.isChecked),
1651+
);
1652+
expect(uncheckedNode.getSemanticsData().role, SemanticsRole.menuItemCheckbox);
1653+
expect(uncheckedNode.getSemanticsData().hasFlag(SemanticsFlag.isButton), isTrue);
1654+
expect(uncheckedNode.getSemanticsData().hasFlag(SemanticsFlag.hasCheckedState), isTrue);
1655+
expect(uncheckedNode.getSemanticsData().hasFlag(SemanticsFlag.isChecked), isFalse);
1656+
1657+
semantics.dispose();
1658+
});
1659+
16071660
testWidgets('PopupMenuButton PopupMenuDivider', (WidgetTester tester) async {
16081661
// Regression test for https://github.com/flutter/flutter/issues/27072
16091662

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/flutter/flutter/commit/7197a8fa9ce68c6d08188b25a8a655e4aacb0030

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy