Skip to content

Commit 491c582

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate no_logic_in_create_state
Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: Idddc688b6a66f1dd03e994af5648d33ca4953441 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390083 Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Phil Quitslund <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent fa09c07 commit 491c582

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pkg/linter/lib/src/rules/no_logic_in_create_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class _Visitor extends SimpleAstVisitor<void> {
4141

4242
var parent = node.parent;
4343
if (parent is! ClassDeclaration ||
44-
!isStatefulWidget(parent.declaredElement)) {
44+
!isStatefulWidget2(parent.declaredFragment?.element)) {
4545
return;
4646
}
4747
var body = node.body;

pkg/linter/lib/src/util/flutter_utils.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ bool isState(InterfaceElement element) => _flutter.isState(element);
4545
bool isStatefulWidget(ClassElement? element) =>
4646
element != null && _flutter.isStatefulWidget(element);
4747

48+
bool isStatefulWidget2(ClassElement2? element) =>
49+
element != null && _flutter.isStatefulWidget2(element);
50+
4851
bool isWidgetProperty(DartType? type) {
4952
if (isWidgetType(type)) {
5053
return true;
@@ -114,6 +117,11 @@ class _Flutter {
114117
bool isExactly(InterfaceElement element, String type, Uri uri) =>
115118
element.name == type && element.source.uri == uri;
116119

120+
/// Whether [element] is exactly the element named [type], from Flutter.
121+
bool isExactly2(InterfaceElement2 element, String type, Uri uri) =>
122+
element.name == type &&
123+
element.firstFragment.libraryFragment.source.uri == uri;
124+
117125
bool isExactWidget(ClassElement element) =>
118126
isExactly(element, _nameWidget, _uriFramework);
119127

@@ -145,6 +153,11 @@ class _Flutter {
145153
element.allSupertypes.any((type) =>
146154
isExactly(type.element, _nameStatefulWidget, _uriFramework));
147155

156+
bool isStatefulWidget2(ClassElement2 element) =>
157+
isExactly2(element, _nameStatefulWidget, _uriFramework) ||
158+
element.allSupertypes.any((type) =>
159+
isExactly(type.element, _nameStatefulWidget, _uriFramework));
160+
148161
bool isWidget(InterfaceElement element) {
149162
if (isExactly(element, _nameWidget, _uriFramework)) {
150163
return true;

0 commit comments

Comments
 (0)