avoid-redundant-semantics-wrapper
Warns when the child widget of Semantics already registers its own semantic node.
Standard Material widgets (ElevatedButton, TextButton, OutlinedButton, IconButton) natively register their own semantics nodes and button role flags.
Wrapping them in an outer Semantics(button: true, label: ...) duplicates accessibility metadata, generating double announcements or conflicting focus nodes.
⚙️ Config
Set additional-widgets (default is empty) to add additional widgets to the list of widgets that registers their own semantics node.
analysis_options.yaml
dcm:
rules:
- avoid-redundant-semantics-wrapper:
additional-methods:
- CustomButton
- CustomSwitch
Example
❌ Bad:
// LINT: The child widget already registers its own semantic node, adding 'Semantics' will cause duplicate announcements.
// Try removing this widget.
Semantics(child: ElevatedButton());
// LINT: The child widget already registers its own semantic node, adding 'Semantics' will cause duplicate announcements.
// Try removing this widget.
Semantics(child: flag ? ElevatedButton() : ElevatedButton());
// LINT: The child widget already registers its own semantic node, adding 'Semantics' will cause duplicate announcements.
// Try removing this widget.
Semantics(child: nullable ?? ElevatedButton());
✅ Good:
ElevatedButton();
Semantics(child: WidgetWithoutItsSemantics());