Skip to content

Commit 984242e

Browse files
zemanuxchunhtailoic-sharma
authored
Deprecate containsSemantics (#12891)
_Issues fixed by this PR (if any):_ flutter/flutter#180534 _PRs or commits this PR depends on (if any):_ flutter/flutter#180538 cc @loic-sharma @chunhtai ## Presubmit checklist - [X] If you are unwilling, or unable, to sign the CLA, even for a _tiny_, one-word PR, please file an issue instead of a PR. - [X] If this PR is not meant to land until a future stable release, mark it as draft with an explanation. - [X] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style)—for example, it doesn't use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first-person pronouns). - [X] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer. --------- Co-authored-by: chunhtai <47866232+chunhtai@users.noreply.github.com> Co-authored-by: Loïc Sharma <737941+loic-sharma@users.noreply.github.com>
1 parent b2b61e5 commit 984242e

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: Deprecate `containsSemantics` in favor of `isSemantics`
3+
description: >
4+
The `containsSemantics` matcher has been deprecated in favor of
5+
`isSemantics` and `matchesSemantics` matchers.
6+
---
7+
8+
{% render "docs/breaking-changes.md" %}
9+
10+
## Summary
11+
12+
The `containsSemantics` partial matcher is deprecated and replaced by
13+
`isSemantics` to clarify intent and standardize matcher conventions.
14+
15+
## Context
16+
17+
The `contains` prefix for partial matchers, such as `containsSemantics`, has been
18+
replaced with `is` to align with naming conventions:
19+
20+
* **Partial matchers** (e.g. `isSemantics`) match only the properties explicitly
21+
provided. Any arguments not provided are ignored.
22+
* **Exact matchers** (e.g. `matchesSemantics`) verify all values. Any arguments
23+
not provided are expected to match the object's default values.
24+
25+
## Migration guide
26+
27+
To automatically migrate your code, run the following command:
28+
29+
```bash
30+
dart fix --apply
31+
```
32+
33+
Alternatively, replace `containsSemantics` with `isSemantics` for partial
34+
matching (most common case), or `matchesSemantics` if you need to assert
35+
exact property values (including defaults for omitted arguments).
36+
37+
Code before migration:
38+
39+
```dart
40+
expect(
41+
tester.getSemantics(find.byType(MyWidget)),
42+
containsSemantics(
43+
label: 'My Widget',
44+
isButton: true,
45+
),
46+
);
47+
```
48+
49+
Code after migration:
50+
51+
```dart
52+
expect(
53+
tester.getSemantics(find.byType(MyWidget)),
54+
isSemantics(
55+
label: 'My Widget',
56+
isButton: true,
57+
),
58+
);
59+
```
60+
61+
## Timeline
62+
63+
Landed in version: 3.40.0-1.0.pre
64+
In stable release: 3.40
65+
66+
## References
67+
68+
API documentation:
69+
70+
* [`isSemantics`][]
71+
* [`matchesSemantics`][]
72+
73+
Relevant issues:
74+
75+
* [Issue 180534][]
76+
* [Issue 107859][]
77+
78+
Relevant PR:
79+
80+
* [PR 180538][]
81+
82+
<!-- Stable channel link: -->
83+
[`isSemantics`]: {{site.api}}/flutter/flutter_test/isSemantics.html
84+
[`matchesSemantics`]: {{site.api}}/flutter/flutter_test/matchesSemantics.html
85+
[Issue 180534]: {{site.repo.flutter}}/issues/180534
86+
[Issue 107859]: {{site.repo.flutter}}/issues/107859
87+
[PR 180538]: {{site.repo.flutter}}/pull/180538

src/content/release/breaking-changes/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ They're sorted by release and listed in alphabetical order:
4040
* [Stop generating `AssetManifest.json`][]
4141
* [`$FLUTTER_ROOT/version` replaced by `$FLUTTER_ROOT/bin/cache/flutter.version.json`][]
4242
* [`FontWeight` also controls the weight attribute of variable fonts][]
43+
* [Deprecate `containsSemantics` in favor of `isSemantics`][]
4344
* [Deprecate `findChildIndexCallback` in favor of `findItemIndexCallback` in `ListView` and `SliverList` separated constructors][]
4445
* [Migrating Flutter Android app to Android Gradle Plugin 9.0.0][]
4546
* [Material 3 tokens update][]
@@ -48,6 +49,7 @@ They're sorted by release and listed in alphabetical order:
4849
[Stop generating `AssetManifest.json`]: /release/breaking-changes/asset-manifest-dot-json
4950
[`$FLUTTER_ROOT/version` replaced by `$FLUTTER_ROOT/bin/cache/flutter.version.json`]: /release/breaking-changes/flutter-root-version-file
5051
[`FontWeight` also controls the weight attribute of variable fonts]: /release/breaking-changes/font-weight-variation
52+
[Deprecate `containsSemantics` in favor of `isSemantics`]: /release/breaking-changes/deprecate-contains-semantics
5153
[Deprecate `findChildIndexCallback` in favor of `findItemIndexCallback` in `ListView` and `SliverList` separated constructors]: /release/breaking-changes/separated-builder-find-child-index-callback
5254
[Migrating Flutter Android app to Android Gradle Plugin 9.0.0]: /release/breaking-changes/migrate-to-agp-9
5355
[Material 3 tokens update]: /release/breaking-changes/material-color-utilities

0 commit comments

Comments
 (0)