Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues in the finding Flutter widgets #42

Closed
singlesoup opened this issue Nov 21, 2022 · 4 comments
Closed

Issues in the finding Flutter widgets #42

singlesoup opened this issue Nov 21, 2022 · 4 comments

Comments

@singlesoup
Copy link

Hello, I am using Custom_lint Package. To write some project specific lints. Like I want my team to use a project specific CustomScaffold rather flutter given Scaffold.

But since this is build on top on Dart Analyzer, which has no way of identifying Flutter Widgets, how can we detect Flutter Widgets with this ?

Tried both Element Tree as well as AST, but since in the documentation there was no mention of Flutter widget, it didn't help much. So it would be amazing if you guys could find some time to see how can we detect Flutter widgets with this.

@singlesoup singlesoup changed the title Issues in the finding Flutter widgets return in the Build(). Issues in the finding Flutter widgets Nov 21, 2022
@rrousselGit
Copy link
Collaborator

You'll want to visit the AST of the build function. From there, search for an ast is InstanceCreation AST (or something with a similar class name, can't remember exactly which one)

With that done, you can obtain the Element. Doing element is ClassElement will give you info about the class instantiated

@singlesoup
Copy link
Author

singlesoup commented Nov 22, 2022

I have tried obataining Element from InstanceCreationExpression by visiting Build Class Members, as you mentioned. But was not able to find any Element. Would it be possible for you point me to the direction where I can get Element from Instance Creation?

@rrousselGit
Copy link
Collaborator

There's InstanceCreationExpression.staticType which is a DartType. And you can access an Element from with with .element

@singlesoup
Copy link
Author

singlesoup commented Nov 22, 2022

hey thanks @rrousselGit , was able to solve the issue.

PS: A small suggestion, if this comes in the package documentations that would be amazing for everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants