0

I'm new to flutter, so I hope my question will not be too much out of scope:

I would like to extract meta informations about the app at build time. The idea is to have JSON tree of the app widgets and send it to an external database via API call for further statistics

Here is a simplified example of my app structure

Scaffold
├─ Page1: homePage
│ ├── BtnWidget: btn1
│ └── RandomWidget
└─ Page2: profilePage
  └── BtnWidget: btn2

And ideally I would like to be able to retrieve something like:

{
  "homePage": { // identifier is used when found to uniquely describe a widget
    "type": "screen",
    "children": ["btn1"], // hierarchical information
    "parent": null,
  },
  ...
}

Is it possible to access the widget list and their properties in code at build time ? Or anytime ?


My researchs:

I have looked this package: build that seems a good lead but I didn't fully understood how it worked for my purpose I have also searched on google or stack overflow but couldn't find nothing relevant


The goal:

When I build a new application, the widget tree and some meta data (version, new features...) is send to a database where data are crossed with user app interaction data (click, swipe...) to track UX statistics along with app versions.

TOPKAT
  • 6,667
  • 2
  • 44
  • 72

1 Answers1

1

It seems what you are looking for is close to debugDumpApp() or debugDumpRenderTree(). Check out this doc https://docs.flutter.dev/testing/code-debugging#render-tree, I guess it's a good starting point.

jjanvier
  • 76
  • 4
  • Hi, nice answer, too bad it doesn't meet the `at build time` requirement...or do I miss something ? – TOPKAT Dec 24 '21 at 16:40
  • You asked "at build time ? Or anytime ?" ^^ Could you maybe precise why you need it at build time? Because if the purpose is just to send the widgets tree somewhere, you could have a simple script or command that builds the app, runs in debug mode and collects the infos, then send them. – jjanvier Dec 24 '21 at 17:40
  • I will be glad to hear about how is that possible :) However I edited the question to clarify the goal – TOPKAT Dec 27 '21 at 08:16