Dart-code: Count widgets and position in dart file

Created on 19 Mar 2019  路  8Comments  路  Source: Dart-Code/Dart-Code

Is it possible to view how many widgets we have in one dart file? For example I need to know how many widgets my build method holds and their current index position.

is question

All 8 comments

The data is likely available in the analysis server (through the flutter outline data), but I'm not sure what a feature to expose this would look like. Could you expand on what you're trying to do, or how you would envisage this working?

I am currently gathering info on developing a plugin for making GUI application for dart, so somehow I need to have control of how my widgets are displayed and in which position it is available in the method:

For example if I have an array of widgets like
var widgets = array[FirstWidget,SecondWidget];
I can easily apply my changes to FirstWidget at index widgets[0],

By plugin, do you mean a VS Code extension? Or something standalone?

Depending on exactly what you're doing, it may be better to build on top of the analyzer directly rather than going through the Dart extension (the analyzer powers all the language features/support - see https://htmlpreview.github.io/?https://github.com/dart-lang/sdk/blob/master/pkg/analysis_server/doc/api.html).

I actually wants to generate dart code from a standalone GUI application, I was thinking to use TypeScript to accomblish it, or maybe dart itself by using flutter-desktop-embedding. I still have not took a decision on this , still on my reasearch for best possible solution. I will check the docs of analyzer, if it can help me to control my widgets position in the code and also give access to features such as hot reload I beleive a standalone solution for my project would be a good choice. If you can provide some other guidance/resources that would be so great of you. Thanks

If you're trying to parse Dart code and can write in Dart, then I think you may benefit from using the analyzer package:

https://pub.dartlang.org/packages/analyzer

However you mention using Hot Reload, which sounds like you want to be able to run Flutter code too. In that case you probably will need to also use the Flutter daemons, which you can find info on here:

https://github.com/flutter/flutter/blob/master/packages/flutter_tools/doc/daemon.md

By running flutter run --machine you get a server you can communicate with JSON that will launch the app and allow you to send commands to hot reload/restart. If you want to see how that works, you can run the Dart: Capture Logs command in VS Code and tick Flutter Run then run a Flutter app and perform some reloads, then click Stop Logging from the notification (which may have collapsed into the notification bell). That will open a log showing you all the JSON that went between VS Code and the Flutter run daemon.

Thank you so much for all the info, it was exactly what the doctor asked.

Dear @DanTup I have a situation where I think you can guide me since I couldn't find any information.

I looked up the docs and found out it was hard to implement an emulator in my case, so I went with "flutter-desktop-embedding" and created an app ( using c#) which embeds the application created by "flutter-desktop-embedding" into my app. Now my issue is I would like to control the widgest being drawn on the canvas, As per my finding I found out that flutter is using Skia canvas to draw items. I want to draw widgets by drag/drop on that canvas, is it possible to control the Skia canvas like that?

@RazaGR unfortunately, I know very little about flutter-desktop-embedding at this point. I think the best place for your questions would be the flutter-desktop-embedding mailing list at https://groups.google.com/forum/#!forum/flutter-desktop-embedding-dev. There are likely many people on that list that have used the project, as well as the developers of the project.

Hope you manage to find what you need!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mccadi picture mccadi  路  3Comments

Matt-Gleich picture Matt-Gleich  路  4Comments

atreeon picture atreeon  路  5Comments

FeimiSzy picture FeimiSzy  路  4Comments

DanTup picture DanTup  路  4Comments