'Accessing widget from ANTLR 4 dart parser

I want to analyze flutter source code in order to determine whether a Text widget is used, its content "text" and it's line. As far as i know i can access the getText() and getLine() methods with any of the ctx provided by the Listener.

I do this with Functions, for example. (This is java code)

@Override public void enterFunctionSignature(Dart2Parser.FunctionSignatureContext ctx) {
        Token methodName = ctx.getStart();
        String text = ctx.getStart().getText();
        Integer line = ctx.getStart().getLine();
        methods.add(methodName);
    }

i use the getLine() somewhere else directly from the returned Token by getStart().

Anyway, the dart2Parser does not include in any way a token for a widget obviously, and as this answer points out, there could be a way to access them with "Object Literals".

However, i havent found a way to print the Widgets or their contents while running the ParsetreeWalker. So is there any way to access them, or would i need to make a custom grammar for that?

EDIT

For example, in this flutter code there is a Text widget used, and i would like to be able to extract "Settings", or whatever string is being injected in that widget. Important to mention that this section of code is deep inside an Scaffold, so id need to be able to get inside it first. (code is too large to show, unless requested)

ListTile(
                leading: Icon(Icons.settings),
                title: Text("Settings",style: TextStyle(fontSize:16.0)),
                onTap: (){
                  if(!_loading){
                    Navigator.push(context,MaterialPageRoute(builder: (context) => Settings()));
                  }
                }
            ),


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source